-
Notifications
You must be signed in to change notification settings - Fork 2
/
markdown.py
executable file
·41 lines (33 loc) · 1019 Bytes
/
markdown.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/python3
from recipe_scrapers import scrape_me
import json, sys
from pathlib import Path
DEFAULT_CONFIG = {
"local": str(Path.home()/"recipes")
}
APPLIED_CONFIG = {}
# load or create config
configPath = Path.home()/"recipes.conf"
if configPath.exists():
if not configPath.is_file():
raise Exception("Config path exists but is not a regular file!")
try:
config = json.loads(configPath.read_text())
except:
config = DEFAULT_CONFIG
else:
config = DEFAULT_CONFIG
configPath.write_text(json.dumps(config))
APPLIED_CONFIG = config
uri = sys.argv[1]
recipe = scrape_me(uri, wild_mode=True)
output = f"# {recipe.title()}\n\n"
if len(recipe.ingredient_groups()) > 1:
raise Exception("multiple ingredient groups not yet implemented")
else:
for ingredient in recipe.ingredients():
output += f"- {ingredient}\n"
output += "\n## Instructions\n\n"
for instruction in recipe.instructions_list():
output += f"{instruction}\n\n"
print(output)