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