Compare commits

...

2 Commits

Author SHA1 Message Date
gauthiier 870dd695b0 arg --interactive 2026-06-09 15:29:47 +02:00
gauthiier aa867adc18 make script 2026-06-09 09:19:38 +02:00
3 changed files with 69 additions and 9 deletions
+8 -1
View File
@@ -1,4 +1,4 @@
import pathlib, re, frontmatter, markdown, citeproc, json
import argparse, pathlib, re, frontmatter, markdown, citeproc, json
from pyzotero import zotero
from html.parser import HTMLParser
import utils
@@ -66,6 +66,10 @@ def format_filename_title(data_csl:dict, bib_entry:str):
if __name__ == "__main__":
p = argparse.ArgumentParser(description="Fetch zotero bibliography")
p.add_argument("--interactive", default=False, action=argparse.BooleanOptionalAction, help="make interactive")
args = p.parse_args()
conf = utils.load_conf()
z = zotero.Zotero(conf['zotero_group_id'], conf['zotero_lib_type'], conf['zotero_api_key'])
@@ -125,8 +129,11 @@ if __name__ == "__main__":
## selective update
new = format_reading(title=title, desc=bib_entry)
if(args.interactive):
updated = update_reading(prev, new)
utils.save_file(filepath, frontmatter.dumps(updated), overwrite=True)
else:
utils.save_file(filepath, frontmatter.dumps(new), overwrite=True)
print(f"reading {e} updated")
+12 -4
View File
@@ -1,4 +1,4 @@
import pathlib, ics, requests, arrow, frontmatter
import argparse, pathlib, ics, requests, arrow, frontmatter
import utils
DFMT = "YYYY-MM-DD"
@@ -22,8 +22,8 @@ def format_event(title:str, date:str, location:str, desc:str):
def compare_events(path:pathlib.PosixPath, title:str, date:str, location:str, desc:str):
p = frontmatter.load(path)
pd = p.to_dict()
pd['content'] = pd['content'].strip()
return p, (pd == {'title': title, 'date': date, 'location': location, 'type': 'event', 'content': desc.strip()})
pd['content'] = pd['content'].strip() if pd['content'] else ''
return p, (pd == {'title': title, 'date': date, 'location': location, 'type': 'event', 'content': desc.strip() if desc else ''})
def update_event(previous:frontmatter.Post, new:frontmatter.Post):
keys = set(previous.keys()).union(set(new.keys()))
@@ -50,6 +50,10 @@ def read_date(p:frontmatter.Post):
if __name__ == "__main__":
p = argparse.ArgumentParser(description="Fetch ICS calendar")
p.add_argument("--interactive", default=False, action=argparse.BooleanOptionalAction, help="make interactive")
args = p.parse_args()
conf = utils.load_conf()
req = requests.get(conf['ics_url']).text
@@ -61,7 +65,8 @@ if __name__ == "__main__":
name = e.name.replace(' ', '-')
fm_date = e.begin.format(DFMT)
fm_date_interval = f"{e.begin.format(DHFMT)}-{e.end.format(HFMT)}"
filename = f'{fm_date}-{name}.md'
# filename = f'{fm_date}-{name}.md'
filename = e.uid + '.md'
filepath = pathlib.Path(conf['content']) / 'events' / filename
if not filepath.exists():
@@ -80,8 +85,11 @@ if __name__ == "__main__":
## selective update
new = format_event(title=e.name, date=fm_date_interval, location=e.location, desc=e.description)
if(args.interactive):
updated = update_event(prev, new)
utils.save_file(filepath, frontmatter.dumps(updated), overwrite=True)
else:
utils.save_file(filepath, frontmatter.dumps(new), overwrite=True)
print(f"event {e.name} updated")
Executable
+45
View File
@@ -0,0 +1,45 @@
#!/bin/bash
if ! [[ "$1" =~ ^(install|bib|cal|output|all|clean) ]]; then
echo "usage: $0 [action]"
echo "where action can be: [install|bib|cal|output|all|clean]"
exit 1
fi
case $1 in
install)
echo "intalling virtual environment"
python -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
echo "make sure to edit the config file conf.edit-me.yml"
;;
bib)
echo "fetching bibliography"
python fetch_bib.py
;;
cal)
echo "fetching calendar"
python fetch_ics.py
;;
output)
echo "creating output"
python make.py
;;
all)
echo "fetching calendar + bibliography + creating output"
python fetch_bib.py
python fetch_ics.py
python make.py
;;
clean)
echo "cleaning virtual environment"
rm -rf venv
rm -rf __pycache__
;;
esac