Skip to content

Commit

Permalink
Was broken: fixed
Browse files Browse the repository at this point in the history
fixes #1
* Fixed issues caused by changes in FAA DOF site.
* remotezip.py: Updated to Python 2.7.
  • Loading branch information
JeffJacobson committed Jul 14, 2015
1 parent f261956 commit 7449fb6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
*.gdb
*.pyc
*.pyproj
*.sln
*.suo
.project
.pydevproject
Scripts/tmp/*
Expand Down
14 changes: 7 additions & 7 deletions faadof.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def createDofGdb(gdbPath, currencyDate=None):
createCurrencyDateTable(gdbPath, currencyDate=currencyDate)


def downloadDofs(url="http://tod.faa.gov/tod/public/DOFS/", datafiles=('53-WA.Dat',), destDir="../Scratch", lastCurrencyDate=None):
def downloadDofs(url="http://tod.faa.gov/tod/public/", index_url="http://tod.faa.gov/tod/public/TOD_DOF.html", datafiles=('53-WA.Dat',), destDir="../Scratch", lastCurrencyDate=None):
"""Downloads the specified data files from the FAA website.
@param url: The URL of the directory that contains the DOF data zip archives.
@type url: str
Expand All @@ -506,22 +506,22 @@ def downloadDofs(url="http://tod.faa.gov/tod/public/DOFS/", datafiles=('53-WA.Da
@rtype: list or None
"""
# This regular expression matches the links to the DOF_* zip files. Captures are 2-digit year, month, and day, respectively.
linkRe = re.compile(r"""<a href=['"](?P<path>/tod/public/DOFS/DOF_(\d{2})(\d{2})(\d{2})\.zip)['"]>""", re.IGNORECASE)
linkRe = re.compile(r"""<a href=['"](?P<path>DOFS/DOF_(\d{2})(\d{2})(\d{2})\.zip)['"]>""", re.IGNORECASE)

print "Reading '%s'..." % url
# Open the page and store the HTML in a variable.
f = urllib2.urlopen(url)
f = urllib2.urlopen(index_url)
html = f.read()
del f # Delete references to unused variables.

# Extract all of the DOF URLs
matches = linkRe.findall(html)
# sample matches:
#[
# ('/tod/public/DOFS/DOF_111020.zip', '11', '10', '20'),
# ('/tod/public/DOFS/DOF_111215.zip', '11', '12', '15'),
# ('/tod/public/DOFS/DOF_120108.zip', '12', '01', '08'),
# ('/tod/public/DOFS/DOF_120304.zip', '12', '03', '04')
# ('DOFS/DOF_111020.zip', '11', '10', '20'),
# ('DOFS/DOF_111215.zip', '11', '12', '15'),
# ('DOFS/DOF_120108.zip', '12', '01', '08'),
# ('DOFS/DOF_120304.zip', '12', '03', '04')
#]
# Convert the matches into a dictionary containing keys "url" and "date".
data = map(lambda s: {
Expand Down
35 changes: 16 additions & 19 deletions remotezip.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ def open(self, name, pwd=None):
offset += fheader[_FH_FILENAME_LENGTH]+fheader[_FH_EXTRA_FIELD_LENGTH]
f = _http_get_partial_data(self.url, offset, offset+fheader[_FH_COMPRESSED_SIZE]-1)
data = f.read()
#return ZipExtFile(cStringIO.StringIO(data), 'r', zinfo)
return ZipExtFile(cStringIO.StringIO(data), zinfo)
return ZipExtFile(cStringIO.StringIO(data), 'r', zinfo)
#return ZipExtFile(cStringIO.StringIO(data), zinfo)


if __name__ == "__main__":
Expand All @@ -296,23 +296,20 @@ def open(self, name, pwd=None):
dest_fname = join(destDir, basename(fname))
print "Extracing %s to %s" % (source_name, dest_fname)

#=======================================================================
# #This is the original code block as written by the original author. It does not work in Python 2.6, though.
# with hzfile.open(source_name) as f:
# data = f.read()
# new_file = open(dest_fname, 'wb')
# new_file.write(data)
# new_file.close()
#=======================================================================

f = hzfile.open(source_name)
new_file = None
try:
with hzfile.open(source_name) as f:
data = f.read()
new_file = open(dest_fname, 'wb') # must open file as binary (unless you know you're only dealing with text files).
new_file = open(dest_fname, 'wb')
new_file.write(data)
new_file.close()
finally:
f.close()
if new_file is not None:
new_file.close()

##f = hzfile.open(source_name)
##new_file = None
##try:
## data = f.read()
## new_file = open(dest_fname, 'wb') # must open file as binary (unless you know you're only dealing with text files).
## new_file.write(data)
## new_file.close()
##finally:
## f.close()
## if new_file is not None:
## new_file.close()

0 comments on commit 7449fb6

Please sign in to comment.