소스 검색

Added start of inventory module.

master
Trey Del Bonis 2 년 전
부모
커밋
cc5e987a98
2개의 변경된 파일32개의 추가작업 그리고 0개의 파일을 삭제
  1. 4
    0
      .gitignore
  2. 28
    0
      inventory.py

+ 4
- 0
.gitignore 파일 보기

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

# Emacs
*~


+ 28
- 0
inventory.py 파일 보기

@@ -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…
취소
저장