|
|
|
|
|
|
|
|
|
|
|
import os |
|
|
|
|
|
import json |
|
|
|
|
|
|
|
|
|
|
|
def get_datadir(): |
|
|
|
|
|
return os.getenv('SB_DATADIR') |
|
|
|
|
|
|
|
|
|
|
|
def get_article_path(slug): |
|
|
|
|
|
return os.path.join(get_datadir(), 'articles', slug + '.json') |
|
|
|
|
|
|
|
|
|
|
|
def load_article_by_slug(slug): |
|
|
|
|
|
with open(get_article_path(slug), 'r') as f: |
|
|
|
|
|
return json.load(f) |
|
|
|
|
|
|
|
|
|
|
|
def save_article(data): |
|
|
|
|
|
with open(get_article_path(data['slug']), 'r') as f: |
|
|
|
|
|
return json.save(data, f) |
|
|
|
|
|
|
|
|
|
|
|
def get_date_report_path(date): |
|
|
|
|
|
dstr = date.strftime('%Y-%m-%d') |
|
|
|
|
|
return os.path.join(get_datadir(), 'days', dstr + '.json') |
|
|
|
|
|
|
|
|
|
|
|
def load_date_report(date): |
|
|
|
|
|
with open(get_date_report_path(date), 'r') as f: |
|
|
|
|
|
return json.load(f) |
|
|
|
|
|
|
|
|
|
|
|
def save_date_report(date, data): |
|
|
|
|
|
with open(get_date_report_path(date), 'w') as f: |
|
|
|
|
|
json.dump(data, f) |