Perhaps I should back up a bit to explain what I’m trying to do.
I’m trying to make an app that will notify me half hour before it is sunset. I like to work on my blueprints up in the mountains however I have a habit of losing track of time and getting stuck up there in the dark. IT would be a lot easier if I knew where I was going to be every day however due to travel I am constantly at different places between Sacramento and Dover. So I want to make an application that can programatically get the data from http://www.timeanddate.com/worldclock/sunrise.html. That website contains a dropdown list where a location is selected and then it takes you to a table that contains the sunset time for the day (and other information not relevant to me).
I ran the process through a program called Fiddler and found that it uses a get request on the value selected in the dropdown box. For example, when I select USA – California – Sacramento the web traffic (according to fiddler) is as follows:
GET http://www.timeanddate.com/worldclock/astronomy.html?n=217 200 OK
(text/html)
So, I think I can pass the n=217 in a WebRequest
WebRequest request = WebRequest.Create("http://www.timeanddate.com/worldclock/astronomy.html?n=217");
request.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
But the problem is I need my program to select Sacramento or Dover etc in code. I Imagine something like
public string GetCityValue(string city)
{
string cityvalue = null;
if (city.Contains("Sacramento"))
{
cityvalue = "217";
}
if (city.Contains("Dover"))
{
cityvalue = "217";
}
return cityvalue;
}
Or perhaps there is a way to put all the dropdown list otions into a list and search the list for the string in the method parameter, anyway those details dont worry me for now. Mostly I just am confused on how I can select a city from the list and get the table on generated page with my own code.
Please let me know if I failed to give necessary information and such.
Thanks
This seems like a use case for a dictionary:
You may want to put this mapping into an XML file so you can more easily update and change it. For example given this XML:
You could create your cityMapping dictionary like this: