Created
November 2, 2014 10:41
-
-
Save fourohfour/c0e32814904f51715667 to your computer and use it in GitHub Desktop.
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 urllib.request | |
def getDimensions(url, data): | |
req = urllib.request.Request(url) | |
page = urllib.request.urlopen(req) | |
pstr = page.read() | |
psplit = str(pstr).split("Dimensions") | |
info = "" | |
for char in psplit[1]: | |
info = info + char | |
try: | |
end = info[-3:] | |
if end == "<b>": | |
info = info[:-3] | |
break | |
except: pass | |
info = info.lower() | |
parts = info.split("\\n") | |
infopart = "" | |
for i in parts: | |
if "wing span" in i: | |
infopart = i.strip("<p>") | |
infodic = {} | |
for i in data: | |
index = infopart.find(i) | |
result = "" | |
if not index == -1: | |
index = index + len(i) | |
while True: | |
char = infopart[index] | |
if not char == "(": | |
result = result + char | |
else: | |
infodic[i] = result.lstrip().rstrip() | |
break | |
index +=1 | |
return infodic | |
ratiolist = [] | |
for i in range(1, 409): | |
print("Airplane " + str(i) + " of 408:") | |
try: | |
dim = getDimensions("http://www.airliners.net/aircraft-data/stats.main?id=" + str(i), ["wing span", "length"]) | |
wspan = float(dim["wing span"].strip("m")) | |
length = float(dim["length"].strip("m")) | |
ratio = wspan / length | |
print("Wingspan: ", wspan) | |
print("Length: ", length) | |
print("Ratio: ", ratio) | |
ratiolist.append(ratio) | |
except: | |
print("Could not get data. Moving on...") | |
print() | |
print("Average: ", (sum(ratiolist) / len(ratiolist))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment