Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

let users of the module to determine their logging configuration #32

Merged
merged 2 commits into from
Mar 5, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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