Browse Source

Added start of inventory module.

master
Trey Del Bonis 2 years ago
parent
commit
cc5e987a98
2 changed files with 32 additions and 0 deletions
  1. 4
    0
      .gitignore
  2. 28
    0
      inventory.py

+ 4
- 0
.gitignore View File

@@ -1,3 +1,7 @@
# Us
_test/
cookies.txt

# Emacs
*~


+ 28
- 0
inventory.py View File

@@ -0,0 +1,28 @@
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)

Loading…
Cancel
Save