move data files out of repo
This commit is contained in:
@@ -8,9 +8,9 @@ def format_timestamp(timestamp):
|
||||
return datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
||||
def parse_foods_file():
|
||||
path = Path.home() / 'projects' / 'open-journal' / 'foods'
|
||||
path = Path.home() / 'workspace' / 'journal' / 'foods'
|
||||
text = path.read_text()
|
||||
foods, recipes_str = text.split('---')
|
||||
foods_str, recipes_str = text.split('---')
|
||||
|
||||
def parse_macro(macro):
|
||||
if macro == '...':
|
||||
@@ -22,7 +22,7 @@ def parse_foods_file():
|
||||
|
||||
foods = {
|
||||
macros[0]: dict(parse_macro(macro) for macro in macros[1:])
|
||||
for macros in [food.split('\n') for food in foods.strip().split('\n\n')]
|
||||
for macros in [food.split('\n') for food in foods_str.strip().split('\n\n')]
|
||||
}
|
||||
|
||||
def combine_values(fst, snd):
|
||||
@@ -100,7 +100,8 @@ def evaluate_food_entry(foods, recipes, value, name):
|
||||
food = {k: v*(value/100.0) for k,v in foods[name].items()}
|
||||
else:
|
||||
breakpoint()
|
||||
print(f'ERROR: Invalid diet entry: {content}')
|
||||
print(f'ERROR: Invalid diet entry: {name}')
|
||||
assert False
|
||||
|
||||
return food
|
||||
|
||||
|
||||
@@ -17,11 +17,11 @@ target_page = journal_path / f'{current_date}.md'
|
||||
script_path = Path(__file__).parent
|
||||
|
||||
habits = '\n'.join([f'[-] {x}'
|
||||
for x in (script_path / 'habits').read_text().strip().split('\n')])
|
||||
for x in (journal_path / 'habits').read_text().strip().split('\n')])
|
||||
|
||||
words = (script_path / 'godword').read_text().strip().split('\n')
|
||||
words = (journal_path / 'godword').read_text().strip().split('\n')
|
||||
godword = '\n'.join(' '.join(random.choice(words)
|
||||
for a in range(10)) for _ in range(2))
|
||||
for __ in range(10)) for _ in range(2))
|
||||
|
||||
if not target_page.exists():
|
||||
Popen(
|
||||
@@ -43,23 +43,22 @@ if not target_page.exists():
|
||||
block['message']
|
||||
))
|
||||
|
||||
parts = [
|
||||
f'# {target_page.stem}',
|
||||
f'Godword:\n{godword}',
|
||||
f'Habits:\n{habits}',
|
||||
]
|
||||
|
||||
if notifications:
|
||||
notifications_rendered = '\n'.join(
|
||||
f'[[{entry}]] {message}'
|
||||
for entry, message in notifications
|
||||
)
|
||||
|
||||
target_page.write_text(f'''\
|
||||
# {target_page.stem}
|
||||
parts.append(f'Notifications:\n{notifications_rendered}')
|
||||
|
||||
Godword:
|
||||
{godword}
|
||||
|
||||
Habits:
|
||||
{habits}
|
||||
|
||||
Notifications:
|
||||
{notifications_rendered}
|
||||
''')
|
||||
header = '\n\n'.join(parts)
|
||||
target_page.write_text(header)
|
||||
|
||||
with open(target_page, 'a') as fp:
|
||||
fp.write(f'\n{current_date} {current_time} ')
|
||||
|
||||
5
parse.py
5
parse.py
@@ -45,6 +45,7 @@ def parse_header(header):
|
||||
title, *modules = split_into_blocks(header)
|
||||
|
||||
for module in modules:
|
||||
print(module)
|
||||
name, value = module.split('\n', maxsplit=1)
|
||||
name = name.lower().removesuffix(':')
|
||||
result[name] = header_modules[name](value)
|
||||
@@ -182,5 +183,7 @@ for fpath in list(sorted((Path.home() / 'workspace' / 'journal').glob('*.md'))):
|
||||
'entries': [parse_entry(e) for e in entries],
|
||||
}
|
||||
|
||||
with open('journal.json', 'w') as fp:
|
||||
script_path = Path(__file__).parent
|
||||
|
||||
with open(script_path / 'journal.json', 'w') as fp:
|
||||
json.dump(result, fp, indent=4, ensure_ascii=False)
|
||||
|
||||
Reference in New Issue
Block a user