diff options
author | Yaron de Leeuw <me@jarondl.net> | 2014-11-24 20:33:36 +0200 |
---|---|---|
committer | Yaron de Leeuw <me@jarondl.net> | 2014-11-27 21:21:20 +0200 |
commit | 61118923218429fffed2146997d8162fe3fee4d0 (patch) | |
tree | 65e66119e5a67c86ddbaa1c3147f459fa9866c12 /updatezinfo.py | |
parent | 4f81f55a6e123c5f079d5a5eeb6a6ea1f58fe644 (diff) | |
download | dateutil-61118923218429fffed2146997d8162fe3fee4d0.tar.gz |
many changes to zoneinfo, and to the download mechanizm
Diffstat (limited to 'updatezinfo.py')
-rwxr-xr-x | updatezinfo.py | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/updatezinfo.py b/updatezinfo.py index 78708ca..ade4d05 100755 --- a/updatezinfo.py +++ b/updatezinfo.py @@ -1,31 +1,29 @@ #!/usr/bin/env python import os import hashlib +import json +import io from six.moves.urllib import request from dateutil.zoneinfo import rebuild - -# ad-hoc solution. TODO: use configuration file or something -TZRELEASES = "ftp://ftp.iana.org/tz/releases/" -TZFILEPATTERN = "tzdata{tag}.tar.gz" -TZTAG = "2014j" -SHA512 = "4c2979be3a96f91f8576304ec905d571b73df0842c8300c1d7317819b45ab3e29948ed911aa265b12a4ad587d5cba44f646dd02e40e4fbf9e68556a2d327142e" - -TZFILE = TZFILEPATTERN.format(tag=TZTAG) +METADATA_FILE = "zonefile_metadata.json" def main(): - if not os.path.isfile(TZFILE): + with io.open(METADATA_FILE,'r') as f: + metadata = json.load(f) + + if not os.path.isfile(metadata['tzdata_file']): print("Downloading tz file from iana") - request.urlretrieve(TZRELEASES + TZFILE, TZFILE) - with open(TZFILE,'rb') as tzfile: + request.urlretrieve(os.path.join(metadata['releases_url'],metadata['tzdata_file']), metadata['tzdata_file']) + with open(metadata['tzdata_file'],'rb') as tzfile: sha_hasher = hashlib.sha512() sha_hasher.update(tzfile.read()) sha_512_file = sha_hasher.hexdigest() - assert SHA512 == sha_512_file, "SHA failed for downloaded tz file" + assert metadata['tzdata_file_sha512'] == sha_512_file, "SHA failed for downloaded tz file" print("Updating timezone information...") - rebuild(TZFILE, TZTAG) + rebuild(metadata['tzdata_file'], zonegroups=metadata['zonegroups']) print("Done.") if __name__ == "__main__": |