arg --interactive
This commit is contained in:
+10
-3
@@ -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)
|
||||
|
||||
updated = update_reading(prev, new)
|
||||
utils.save_file(filepath, frontmatter.dumps(updated), overwrite=True)
|
||||
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")
|
||||
|
||||
|
||||
+14
-6
@@ -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)
|
||||
|
||||
updated = update_event(prev, new)
|
||||
utils.save_file(filepath, frontmatter.dumps(updated), overwrite=True)
|
||||
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")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user