fix basepath

This commit is contained in:
Daniel Tsvetkov 2019-03-13 22:17:34 -07:00
parent 7919d7e95a
commit 1b93a7914a

12
tz.py
View File

@ -1,6 +1,6 @@
"""
"""
import os
import argparse
import logging
import sys
@ -11,6 +11,8 @@ from pytz.exceptions import UnknownTimeZoneError
FUZZ_THRESHOLD = 70
DEFAULT_FORMAT = '%Y-%m-%d %H:%M:%S%z'
basepath = os.path.dirname(os.path.abspath(__file__))
logging.basicConfig()
logger = logging.getLogger()
@ -90,11 +92,10 @@ def create_if_not_exists(fname):
def write_to_cache(query, location):
import os
import csv
logger.debug("Writing location to cache")
with open(os.path.join("data",".cache.csv"), 'a+') as wf:
with open(os.path.join(basepath, "data",".cache.csv"), 'a+') as wf:
cachewriter = csv.writer(wf)
cachewriter.writerow([query,
location.latitude,
@ -113,19 +114,18 @@ def resolve_location_local(query):
"""
Find a location by searching in local db of countries and cities
"""
import os
import csv
from heapq import heappush, heappop
from fuzzywuzzy import fuzz
query = query.lower()
create_if_not_exists(os.path.join("data",".cache.csv"))
create_if_not_exists(os.path.join(basepath, "data",".cache.csv"))
# location hypothesis heap
heap = []
for fname in [".cache", "countries", "cities"]:
with open(os.path.join("data", "{}.csv".format(fname))) as f:
with open(os.path.join(basepath, "data", "{}.csv".format(fname))) as f:
cfile = csv.reader(f)
for row in cfile:
entry = row[0]