Skip to content

Instantly share code, notes, and snippets.

@fourohfour
Created November 2, 2014 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fourohfour/c0e32814904f51715667 to your computer and use it in GitHub Desktop.
Save fourohfour/c0e32814904f51715667 to your computer and use it in GitHub Desktop.
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