Using HttpWebRequest To Download Lottery, Race Track and other Data

by Naveen 13. April 2011 18:31

Automating web actions is one of my favorite things to do when I get some free time. Recently I was building a gaming site where past winning lottery numbers, game results, race track results etc. are going to be analyzed to come up with some interesting predictions. Well, part of the process was to automate downloading of results from various lottery sites, race track sites etc. One more time, I had our easy to use but very powerful HttpWebRequest object come to save the day and help in downloading data files from various sites. Here is a code snippet from what I was implementing.

byte[] data = null;
var webReq = HttpWebRequest.Create(url) as HttpWebRequest;
CookieContainer cookies = new CookieContainer();
webReq.CookieContainer = cookies;
webReq.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)";
HttpWebResponse webResp = webReq.GetResponse() as HttpWebResponse;
byte[] primingData = GetResponseData(webResp);
webResp.Close();

You can see use of CookieContainer object to pass cookies to request and then save cookies from response to pass on to next request. In some of the sites, this was very handy because those sites for relying on some data being present in the cookies. Well those site developers did not tell me what they were doing. But after running into some errors with those sites, I did some experiments and finally figured out what was going on.

If you want to see some of the results I got from this process, goto Latest Lottery Results page and see how I managed to automate downloading of some lottery results and then display them.

 

Views: 1663

Tags:

.Net | Automation

How to uninstall Powershell Cmdlets

by Viper 30. January 2009 10:35

I was looking at Microsoft documentation on how to register custom Cmdlets to install one of my Cmdlets. I realized that I made some mistake in the implementation. So I had to uninstall Cmdlet from shell. You will follow the same instructions from documentation with one change. You can specify /u parameter to InstallUtil to uninstall the assembly. So the command will look following:


PS> set-alias installutil $env:windir\Microsoft.NET\Framework\v2.0.50727\installutil
PS> installutil /u SelectStrCommandSample.dll
Microsoft (R) .NET Framework Installation utility Version 2.0.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.

…
The uninstall has completed.


 

Views: 8249

Tags:

Automation | Powershell

How to uninstall Powershell V1

by Viper 30. January 2009 02:59

If you want to install Pwershell V2.0, one of the requirements is to uninstall previous versions of Powershell. If you don't do that, while installing V2.0, you will get message about uninstalling it. And the message does say to use Add/Remove Programs to uninstall it. So I went to Add/Remove Programs panel and could not find it there. That was frustrating. So I decicded to do some manual search about this installed program. All programs installed on Windows (if done right) have a registry entry at HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall location. If you search on that node for Powershell you will find a key for KB926139-2. Look at value for ParentDisplayName. It points to Windows XP - Software Updates. When we goto Add/Remove Programs control panel, the check box for Show Updates is usually not selected by default. So check that box and you should see all updates. Now you will find Powershell installation under Windows XP- Software Updates (depending on operating system you are using. You can now uninstall it from here. Following screen shot shows registry entry from my machine.

 

Views: 8299

Tags:

Windows | Windows 7 | Automation | Windows 7 | Powershell | Windows | Windows 7

Combining more than one filter in where-object filtering in Powershell

by Viper 29. January 2009 15:37

A lot of time you want to filter your results from Get-* command in Powershell. One way to do will be to pass the results from Get-* command through two where-object pipe lines. Or you can take advantage of logical operators to combine more than one filter in one where-object FilterScript. For example I wanted to get list of processes on my server that are using more than 2MB of memory or have more than 400 file handles open. Following command shows how two filters were combined.

get-process | where {($_.WorkingSet -gt 1024*2048) -or ($_.HandleCount -gt 400)}

Following is list of logical operators that are available in PowerShell.

Logical OperatorMeaning
-andLogical and; true if both sides are true
-orLogical or; true if either side is true
-notLogical not; reverses true and false
!Logical not; reverses true and false
 

Views: 3416

Tags:

Automation | Powershell | Automation

Find day of the week using Powershell command

by Viper 29. January 2009 10:24

I was working on some automation script and somebody asked me whats the day of the week on a certain date. I was like lets see if i can do it without opening up calendar. So i decided to play around with get-date command in Powershell. And there it was, some fun with the command to try different things. Following are some commands that you can try yourself.

How to get day of week


get-date -format dddd

How to get day of week for any date


get-date -format dddd -Year 2010 -Month 2 -Day 28

Notice use of Year, Month and Date parameters. If you omit one of these parameters, then command will use today's component of that parameter.

 

Views: 3971

Tags:

Powershell | Automation

Smart Phones Poll

What smart phone do you currently own?





Show Results

Month List

Powered by BlogEngine.NET 2.0.0.49
Theme by Naveen Kohli