Optimize imports, indent with 4 spaces (PEP8)

This commit is contained in:
Thomas Lauf 2018-01-07 22:08:09 +01:00
parent fdd40c484a
commit 6272f1ad5d

View file

@ -25,14 +25,22 @@
#
###############################################################################
import os, sys, re, time, datetime, json, argparse
import argparse
import json
import os
import re
import sys
import time
if sys.version_info >= (3,0):
import datetime
if sys.version_info >= (3, 0):
from urllib.request import urlopen
from urllib.error import HTTPError
else:
from urllib2 import urlopen, HTTPError
def enumerate(path):
if not os.path.exists(path):
raise Exception("Directory '%s' does not exist" % path)
@ -48,7 +56,7 @@ def holidata(locale, year):
def update_locales(locales, regions, years):
if years == []:
if not years:
years = [datetime.datetime.now().year, datetime.datetime.now().year + 1]
for locale in locales:
@ -71,7 +79,7 @@ def update_locales(locales, regions, years):
day = j['date'].replace("-", "_")
desc = j['description']
data = ' %s = %s\n' % (day, desc)
if sys.version_info >= (3,0):
if sys.version_info >= (3, 0):
fh.write(data)
else:
fh.write(data.encode('utf-8'))
@ -102,7 +110,8 @@ def main(args):
if __name__ == "__main__":
usage = """See http://holidata.net for details of supported locales and regions."""
parser = argparse.ArgumentParser(description="Update holiday data files. Simply run 'refresh' to update all of them.")
parser = argparse.ArgumentParser(
description="Update holiday data files. Simply run 'refresh' to update all of them.")
parser.add_argument('--locale', nargs='+', help='Specific locale to update.')
parser.add_argument('--region', nargs='+', help='Specific locale region to update.')
parser.add_argument('--year', nargs='+', help='Specific year to fetch.', type=int, default=[])
@ -112,4 +121,3 @@ if __name__ == "__main__":
main(args)
except Exception as msg:
print('Error:', msg)