LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-24-2003, 11:32 AM   #1
js_530
Member
 
Registered: Jul 2003
Posts: 162

Rep: Reputation: Disabled
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?
 
Old 08-24-2003, 12:13 PM   #2
js_530
Member
 
Registered: Jul 2003
Posts: 162

Original Poster
Rep: Reputation: Disabled
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?
 
Old 08-24-2003, 01:18 PM   #3
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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
 
Old 08-24-2003, 01:20 PM   #4
js_530
Member
 
Registered: Jul 2003
Posts: 162

Original Poster
Rep: Reputation: Disabled
I already have the text file will all the cities. I don't want to lookup 90 cities by hand.
 
Old 08-24-2003, 02:43 PM   #5
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
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.

Last edited by kev82; 08-24-2003 at 02:44 PM.
 
Old 08-24-2003, 02:44 PM   #6
js_530
Member
 
Registered: Jul 2003
Posts: 162

Original Poster
Rep: Reputation: Disabled
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++
 
Old 08-24-2003, 02:53 PM   #7
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
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
 
Old 08-25-2003, 09:34 AM   #8
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Rep: Reputation: 31
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)

Last edited by Strike; 08-25-2003 at 09:36 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Firefox pauses when scrolling long distances Charred Slackware 5 07-15-2005 02:04 PM
Traceroute, Ping, Domain Name Server (DNS) Lookup, WHOIS, and DNS Records Lookup netoknet General 1 05-09-2005 03:43 AM
change the distances between desktop icons hraposo Debian 2 11-27-2004 11:19 AM
change the distances between the icons in desktop hraposo Slackware 3 11-03-2004 01:49 PM
Samba, a tale of two cities kcourser Linux - Networking 3 03-12-2003 01:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration