move data files out of repo

This commit is contained in:
olari
2021-06-19 11:50:19 +03:00
parent f4c4407ebc
commit 195c430797
6 changed files with 25 additions and 2254 deletions

View File

@@ -8,9 +8,9 @@ def format_timestamp(timestamp):
return datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S') return datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
def parse_foods_file(): def parse_foods_file():
path = Path.home() / 'projects' / 'open-journal' / 'foods' path = Path.home() / 'workspace' / 'journal' / 'foods'
text = path.read_text() text = path.read_text()
foods, recipes_str = text.split('---') foods_str, recipes_str = text.split('---')
def parse_macro(macro): def parse_macro(macro):
if macro == '...': if macro == '...':
@@ -22,7 +22,7 @@ def parse_foods_file():
foods = { foods = {
macros[0]: dict(parse_macro(macro) for macro in macros[1:]) 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): 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()} food = {k: v*(value/100.0) for k,v in foods[name].items()}
else: else:
breakpoint() breakpoint()
print(f'ERROR: Invalid diet entry: {content}') print(f'ERROR: Invalid diet entry: {name}')
assert False
return food return food

1229
foods

File diff suppressed because it is too large Load Diff

1000
godword

File diff suppressed because it is too large Load Diff

3
habits
View File

@@ -1,3 +0,0 @@
take vitamins
weigh yourself
exercise

View File

@@ -17,11 +17,11 @@ target_page = journal_path / f'{current_date}.md'
script_path = Path(__file__).parent script_path = Path(__file__).parent
habits = '\n'.join([f'[-] {x}' 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) 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(): if not target_page.exists():
Popen( Popen(
@@ -43,23 +43,22 @@ if not target_page.exists():
block['message'] block['message']
)) ))
parts = [
f'# {target_page.stem}',
f'Godword:\n{godword}',
f'Habits:\n{habits}',
]
if notifications:
notifications_rendered = '\n'.join( notifications_rendered = '\n'.join(
f'[[{entry}]] {message}' f'[[{entry}]] {message}'
for entry, message in notifications for entry, message in notifications
) )
target_page.write_text(f'''\ parts.append(f'Notifications:\n{notifications_rendered}')
# {target_page.stem}
Godword: header = '\n\n'.join(parts)
{godword} target_page.write_text(header)
Habits:
{habits}
Notifications:
{notifications_rendered}
''')
with open(target_page, 'a') as fp: with open(target_page, 'a') as fp:
fp.write(f'\n{current_date} {current_time} ') fp.write(f'\n{current_date} {current_time} ')

View File

@@ -45,6 +45,7 @@ def parse_header(header):
title, *modules = split_into_blocks(header) title, *modules = split_into_blocks(header)
for module in modules: for module in modules:
print(module)
name, value = module.split('\n', maxsplit=1) name, value = module.split('\n', maxsplit=1)
name = name.lower().removesuffix(':') name = name.lower().removesuffix(':')
result[name] = header_modules[name](value) 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], '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) json.dump(result, fp, indent=4, ensure_ascii=False)