Skip to content

Commit

Permalink
Merge pull request #32 from f0rk/master
Browse files Browse the repository at this point in the history
let users of the module to determine their logging configuration
  • Loading branch information
cstich committed Mar 5, 2016
2 parents fe4a2eb + 40765e3 commit 6294f7e
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions tzwhere/tzwhere.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ class are instantiated and queried directly, but the module can be run
except ImportError:
WRAP = tuple

LOGGER_FORMAT = '%(asctime)-15s %(filename)s %(funcName)s %(lineno)d %(levelname)s %(message)s'
logging.basicConfig(format=LOGGER_FORMAT, level=logging.DEBUG)
LOGGER = logging.getLogger('pytzwhere')


Expand Down Expand Up @@ -261,7 +259,7 @@ def read_tzworld(input_kind='json', path=None):
def read_json(path=None):
if path is None:
path = tzwhere.DEFAULT_JSON
logging.info('Reading json input file: %s\n' % path)
LOGGER.info('Reading json input file: %s\n' % path)
with open(path, 'r') as f:
featureCollection = json.load(f)
return featureCollection
Expand All @@ -270,30 +268,30 @@ def read_json(path=None):
def read_pickle(path=None):
if path is None:
path = tzwhere.DEFAULT_PICKLE
logging.info('Reading pickle input file: %s\n' % path)
LOGGER.info('Reading pickle input file: %s\n' % path)
with open(path, 'rb') as f:
featureCollection = pickle.load(f)
return featureCollection

@staticmethod
def write_pickle(featureCollection, path=DEFAULT_PICKLE):
logging.info('Writing pickle output file: %s\n' % path)
LOGGER.info('Writing pickle output file: %s\n' % path)
with open(path, 'wb') as f:
pickle.dump(featureCollection, f, protocol=2)

@staticmethod
def _read_polygons_from_csv(path=None):
if path is None:
path = tzwhere.DEFAULT_CSV
logging.info('Reading from CSV input file: %s\n' % path)
LOGGER.info('Reading from CSV input file: %s\n' % path)
with open(path, 'r') as f:
for row in f:
row = row.split(',')
yield(row[0], [[float(y) for y in x.split(' ')] for x in row[1:]])

@staticmethod
def write_csv(featureCollection, path=DEFAULT_CSV):
logging.info('Writing csv output file: %s\n' % path)
LOGGER.info('Writing csv output file: %s\n' % path)
with open(path, 'w') as f:
writer = csv.writer(f)
for (tzname, polygon) in tzwhere._feature_collection_polygons(
Expand Down Expand Up @@ -357,14 +355,18 @@ def _feature_collection_polygons(featureCollection):


def main():

LOGGER_FORMAT = '%(asctime)-15s %(filename)s %(funcName)s %(lineno)d %(levelname)s %(message)s'
logging.basicConfig(format=LOGGER_FORMAT, level=logging.DEBUG)

try:
import docopt
except ImportError:
print("Please install the docopt package to use tzwhere.py as a script.")
import sys
sys.exit(1)

logging.info('Application started..')
LOGGER.info('Application started..')
args = docopt.docopt(HELP)

global report_memory
Expand Down

0 comments on commit 6294f7e

Please sign in to comment.