You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

inventory.py 757B

12345678910111213141516171819202122232425262728
  1. import os
  2. import json
  3. def get_datadir():
  4. return os.getenv('SB_DATADIR')
  5. def get_article_path(slug):
  6. return os.path.join(get_datadir(), 'articles', slug + '.json')
  7. def load_article_by_slug(slug):
  8. with open(get_article_path(slug), 'r') as f:
  9. return json.load(f)
  10. def save_article(data):
  11. with open(get_article_path(data['slug']), 'r') as f:
  12. return json.save(data, f)
  13. def get_date_report_path(date):
  14. dstr = date.strftime('%Y-%m-%d')
  15. return os.path.join(get_datadir(), 'days', dstr + '.json')
  16. def load_date_report(date):
  17. with open(get_date_report_path(date), 'r') as f:
  18. return json.load(f)
  19. def save_date_report(date, data):
  20. with open(get_date_report_path(date), 'w') as f:
  21. json.dump(data, f)