summaryrefslogtreecommitdiff
path: root/bin/import_cals.py
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-02-24 23:38:27 +0100
committeremkael <emkael@tlen.pl>2016-02-24 23:41:25 +0100
commit2173f7d7613b5158f4bb2f71a02df353c058c1ee (patch)
treeeac23e40bc497706b862b5d2ca01920c4b37ed92 /bin/import_cals.py
parent6e72eace43adc48f0b311c26d66d13315e25fe93 (diff)
* moving PHP app files to app/php and Python app files to app/python
Diffstat (limited to 'bin/import_cals.py')
-rw-r--r--bin/import_cals.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/bin/import_cals.py b/bin/import_cals.py
index 34e607d..41f5542 100644
--- a/bin/import_cals.py
+++ b/bin/import_cals.py
@@ -20,18 +20,21 @@ CONFIG = json.load(open(
def main():
cal_list = None
- if not os.path.exists(CONFIG['cache']) or \
- int(time.time()) - int(os.path.getmtime(CONFIG['cache'])) > \
+ cache_path = os.path.join(
+ os.path.dirname(os.path.realpath(__file__)),
+ CONFIG['cache'])
+ if not os.path.exists(cache_path) or \
+ int(time.time()) - int(os.path.getmtime(cache_path)) > \
CONFIG['cache_time']:
opener = urllib2.build_opener()
opener.addheaders = [('User-Agent', CONFIG['user_agent'])]
cal_list = json.loads(opener.open(CONFIG['reddit_url']).read())
cal_list = cal_list[0]['data']['children'][0]['data']['selftext']
- with open(CONFIG['cache'], 'w') as cache_file:
+ with open(cache_path, 'w') as cache_file:
cache_file.write(cal_list)
cache_file.close()
else:
- cal_list = open(CONFIG['cache'], 'r').read()
+ cal_list = open(cache_path, 'r').read()
session = Session.create()