git.lirion.de

Of git, get, and gud

aboutsummaryrefslogtreecommitdiffstats
path: root/refresh
diff options
context:
space:
mode:
Diffstat (limited to 'refresh')
-rwxr-xr-xrefresh40
1 files changed, 28 insertions, 12 deletions
diff --git a/refresh b/refresh
index 188f65b..5689f2a 100755
--- a/refresh
+++ b/refresh
@@ -22,7 +22,7 @@ SCRIPT IS NOT FINISHED, THIS IS A GIT - USE ONLY IF YOU UNDERSTAND AND IF YOU AR
"""
#import os, sys, re, time, argparse
-import json, sys
+import json, sys, argparse
reload(sys)
sys.setdefaultencoding('utf8')
from datetime import datetime
@@ -58,7 +58,7 @@ def hfetch(locode, year):
This function downloads the holiday data for a given ISO-3166 code from holidata.net
It will return a single string containing all of the JSON.
"""
- myurl = "https://holidata.net/" + mylocode + "/" + myyear + ".json"
+ myurl = "https://holidata.net/" + locode + "/" + year + ".json"
try:
lines = urlopen(myurl).read().decode('utf-8')
except HTTPError as httpe:
@@ -108,22 +108,38 @@ def hparse(lines, locode, year):
sleep(0.1)
sys.stdout.flush()
-if __name__ == "__main__":
- myyear = ""
- mylocode = ""
- if myyear == "":
+def main(args):
+ if args.locale != "" and args.locale != None:
+ locode = args.locale
+ else:
+ locode = "de-DE"
+ if args.year != None and args.year != []:
+ year = args.locale
+ else:
now = datetime.now()
- myyear = unicode(now.year)
- if mylocode == "":
- mylocode = "de-DE"
+ year = unicode(datetime.now().year)
sys.stdout.write("Fetching holiday data from holidata.net...")
sys.stdout.flush()
- lines = hfetch(mylocode, myyear)
+ lines = hfetch(locode, year)
print(" done.")
if lines == "":
- print("No lines returned from holidata.net for %s!", mylocode)
+ print("No lines returned from holidata.net for %s!", locode)
exit(3)
sys.stdout.write("Parsing data")
sys.stdout.flush()
- hparse(lines, mylocode, myyear)
+ hparse(lines, locode, year)
print(" done.")
+
+if __name__ == "__main__":
+ usage = """See https://holidata.net for details of supported locales and regions."""
+ parser = argparse.ArgumentParser(description="Update holiday data files. Run 'refresh' for \
+ the default of de-DE (this will be changed in the future)")
+ parser.add_argument('--locale', nargs='+', help='Specific locale to update', type=unicode, default="")
+ parser.add_argument('--region', nargs='+', help='Specific locale region to update', type=unicode, default="")
+ parser.add_argument('--year', nargs='+', help='Specific year to fetch.', type=int, default=[])
+ args = parser.parse_args()
+ main(args)
+ #try:
+ # main(args)
+ #except Exception as msg:
+ # print('Error:',msg)