LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Lookup distances between cities in TX? (http://www.linuxquestions.org/questions/programming-9/lookup-distances-between-cities-in-tx-85169/)

js_530 08-24-2003 11:32 AM

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 12:13 PM

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

http://www.indo.com/distance/

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

Dark_Helmet 08-24-2003 01: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 www.mapquest.com, 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 01: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 02: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)

distances.com/find?start=London&end=Edinburgh

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 02:44 PM

I already know the url

http://www.indo.com/cgi-bin/dist?pla...rel+City%2C+TX

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

david_ross 08-24-2003 02:53 PM

Why not run a loop to get:
Code:

lynx -dump "http://www.indo.com/cgi-bin/dist?place1=Dallas%2CTX&place2=Gun+Barrel+City%2C+TX" | grep nautical

Strike 08-25-2003 09:34 AM

Code:

import httplib

cities = ["Houston, TX", "Dallas, TX", ... (fill in the rest here)]
host = "http://www.indo.com"
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)
        else:
            data = response.read()
            # 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 07:34 PM.