Created
May 18, 2014 18:51
-
-
Save dellsystem/0fc0a504ef1d6a6ba9fd to your computer and use it in GitHub Desktop.
Requires two python dependencies: `beautifulsoup4` and `requests` (installable through pip)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from bs4 import BeautifulSoup | |
import requests | |
url = ("http://www.webflyer.com/travel/mileage_calculator/getmileage.php?city=" | |
"%s&city=%s&city=&city=&city=&city=&bonus=0&bonus_use_min=0&class_bonus" | |
"=0&class_bonus_use_min=0&promo_bonus=0&promo_bonus_use_min=0&min=0&min" | |
"_type=m&ticket_price=") | |
def get_distance(airport1, airport2): | |
r = requests.get(url % (airport1, airport2)) | |
# BeautifulSoup doesn't like underscores in class names | |
content = r.content.replace('row_odd_font', 'rowoddfont') | |
soup = BeautifulSoup(content) | |
spans = soup.find_all('span', attrs={'class': 'rowoddfont'}) | |
span = spans[1] | |
text = span.text.split(' ') | |
num_miles = text[0] | |
return num_miles | |
if len(sys.argv) < 3: | |
print "python distance.py {AIRPORT1} {AIRPORT2}" | |
else: | |
print get_distance(sys.argv[1], sys.argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment