Compare commits

...

4 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
gauthiier 2e2da08a09 fetches 2025-09-21 07:32:21 +02:00
gauthiier 5ed1a6ebd7 citeproc 2025-09-21 07:24:54 +02:00
7 changed files with 91 additions and 16 deletions
+2 -2
View File
@@ -1,7 +1,7 @@
conf.yml
public/
content/events
content/bibliography
content/events/
content/bibliography/
# ---> macOS
# General
+15 -2
View File
@@ -2,9 +2,22 @@
Site logics of "Mathematics & Artifice"
'''
Setup:
```
> python -m venv venv
> source venv/bin/activate
> pip install -r requirements.txt
> python make.py
'''
```
Fetch bibliography (make sure conf.yml is set/valid):
```
> python fetch_bib.py
> python make.py
```
Fetch events (make sure conf.yml is set/valid):
```
> python fetch_ics.py
> python make.py
```
+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")
+13 -5
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,8 +65,9 @@ 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'
filepath = pathlib.Path(conf['content']) / 'event' / filename
# filename = f'{fm_date}-{name}.md'
filename = e.uid + '.md'
filepath = pathlib.Path(conf['content']) / 'events' / filename
if not filepath.exists():
print(f"new event: {e.name}")
@@ -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")
+1 -1
View File
@@ -59,7 +59,7 @@ if __name__ == "__main__":
if not events_dir.exists():
print("path content/events does not exist.")
else:
events = list(utils.get_files_in_subdir(conf['content'], 'event', 'md').values())
events = list(utils.get_files_in_subdir(conf['content'], 'events', 'md').values())
for e in events:
p = frontmatter.load(e)
summary = f"{p['title']} - {p['date']}"
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
+2
View File
@@ -3,10 +3,12 @@ attrs==24.2.0
bibtexparser==1.4.2
certifi==2024.8.30
charset-normalizer==3.3.2
citeproc-py==0.6.0
feedparser==6.0.11
ics==0.7.2
idna==3.10
Jinja2==3.1.4
lxml==5.3.0
Markdown==3.7
MarkupSafe==2.1.5
pyparsing==3.1.4