Skip to content

Commit

Permalink
trying auto build
Browse files Browse the repository at this point in the history
  • Loading branch information
JoFrhwld committed Jun 30, 2024
1 parent 9566a28 commit a8f1d03
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 322 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/build-site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Build Site
on:
push:
branches: ["master"]
workflow_dispatch:

jobs:
build-docs:
Expand All @@ -20,6 +21,14 @@ jobs:
run: Rscript -e 'renv::install("reticulate")'
- name: Set up quarto
uses: quarto-dev/quarto-actions/setup@v2
- name: Build Research pages
run: |
python make_research_qmd.py --zotero_key ${{ secrets.ZOTERO_KEY }}
git config user.name 'bot'
git config user.email '...'
git add research/papers/*
git commit -m "gh workflow build [skip actions]"
git push
- name: Render and publish to gh pages
uses: quarto-dev/quarto-actions/publish@v2
with:
Expand Down
55 changes: 55 additions & 0 deletions make_research_qmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from pyzotero import zotero
from zotero2qmd.zotero2qmd import item2main, main2qmd, filter_pubs
from collections import Counter
import re
import yaml
from pathlib import Path
import click


def make_file_names(all_mains):
first_aut = [x["author"][0]["name"]["family"] for x in all_mains]
years = [x["date"].split("-")[0] for x in all_mains]
keys = [x["params"]["key"] for x in all_mains]

all_stem = [f"{aut}_{year}_{key}" for aut, year, key in zip(first_aut, years, keys)]

all_stem = [re.sub(r"_$", "", x) for x in all_stem]
return all_stem

@click.command()
@click.option(
'--zotero_key',
default = ".zotero"
)
def zotero_qmd(
zotero_key
):
if zotero_key == ".zotero":
keypath = Path(".zotero")
with keypath.open() as keyfile:
zotero_key = keyfile.readline().strip()

zot = zotero.Zotero(
library_id='7642731',
library_type='user',
api_key=zotero_key
)

pubs = zot.publications()

filtered_pubs = filter_pubs(pubs)
all_mains = [item2main(x) for x in filtered_pubs]
all_stems = make_file_names(all_mains)
out_path = Path("research","papers")

for stem, item in zip(all_stems, all_mains):
out_file = out_path.joinpath(stem).with_suffix(".qmd")
if not out_file.exists():
with out_file.open(mode = "w"):
qmd_string = "---\n"+yaml.dump(item)+"\n---"
out_file.write_text(qmd_string)


if __name__ == "__main__":
zotero_qmd()
Loading

0 comments on commit a8f1d03

Please sign in to comment.