-   Programming (
-   -   Lookup distances between cities in TX? (

js_530 08-24-2003 12:32 PM

Lookup distances between cities in TX?
For my history homework, I have to lookup the distance between like 60 cities. And, me being lazy, would like to know how to do this in C/C++. I don't know much about sockets (because I used to use dev c, on windows). Is there any cgi-script that it could use and then format the data?

js_530 08-24-2003 01:13 PM

Ok, I've found a website that will get the distance between two cities (seems like there's alot of cities)

But, since I don't know socket programming, could anyone help me?

Dark_Helmet 08-24-2003 02:18 PM

Dude, you're trying to kill a fly with a sledgehammer. You don't need socket programming to look up distances between cities. By the time you've entered the names of each city in a text file, you could have the information already. Just go to, choose driving directions, then enter the city/state combinations.

To get the same result with socket programming you obviously have to set up the program, then you need to figure out the protocol (sounds like HTTP) to communicate with the server, and then parse the the data when it comes back.

If you proclaim to be "lazy" then I guarantee you writing a socket program is most definitely not the path of least resistance.

Just my :twocents:

js_530 08-24-2003 02:20 PM

I already have the text file will all the cities. I don't want to lookup 90 cities by hand.

kev82 08-24-2003 03:43 PM

this is just a rough idea and might be a load of rubbish but anyway, when you goto one of these websites and type in the place names it must go to some html page like(this is made up)

you can see where it goes by looking at the html source and see what happens to the contents of the edit boxes. using perl or awk you could then take your file of places and produce a file containing the url's, you could then run that through wget and get the html pages with all the distances on. which you could then extract with grep.

js_530 08-24-2003 03:44 PM

I already know the url

I need help programming it. It could be in perl/shell/c/c++

david_ross 08-24-2003 03:53 PM

Why not run a loop to get:

lynx -dump "" | grep nautical

Strike 08-25-2003 10:34 AM


import httplib

cities = ["Houston, TX", "Dallas, TX", ... (fill in the rest here)]
host = ""
page =  "/cgi-bin/dist?"

for city1 in cities:
    for city2 in cities:
        param1 = city1.replace(" ", "+")
        param2 = city2.replace(" ", "+")
        params = "place1=%s&place2=%s" % (param1, param2)
        conn = httplib.HTTPConnection(host)
        conn.request("GET", page + params)
        response = conn.getresponse()
        if response.status != 200:
            print "Failed lookup on %s and %s." % (city1, city2)
            data =
            # parse the HTML for your answer here

Tar dar.

(PS - this code was written in oh ... about 5 minutes, maybe less)

All times are GMT -5. The time now is 09:33 AM.