edryd.org

some of my neat stuff
git clone git://edryd.org/edryd.org
Log | Files | Refs | LICENSE

commit 0cd44bc3ed5106715bd759c09b77446da0d68a6e
parent 41a21882c799f43ff5be45d51021f578256f9c9b
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Mon, 22 Feb 2021 22:43:54 -0800

Add mk-content script to fetch project pages

Gets project pages from GitHub repos and gists. Also generates
photos page using shortcode

Diffstat:
mk-content.py | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+), 0 deletions(-)

diff --git a/mk-content.py b/mk-content.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 + +import yaml +import urllib.request +import requests +import shutil + +# TODO flag -v for verbose printing +# TODO flag -d for destination + +# TODO write in tisp +with open('data/projects.yaml') as d: + data = yaml.load(d, Loader=yaml.FullLoader) + # print(data['scripts']) + for gist in data['scripts']: + gid = gist['id'] + r = requests.get('https://api.github.com/gists/' + gid) + desc = r.json()['description'] + title = list(r.json()['files'])[0].split('.')[0].lower() + with open(f'content/projects/{title}.md', 'w') as f: + f.write(f'---\ntitle: {title}\ndescription: {desc}\n---\n') + for file in iter(r.json()['files'].values()): + name = file['filename'] + lang = file['language'].lower() + content = file['content'] + f.write(f'##### {name}:\n') + f.write(f'```{lang}\n{content}\n```\n') + # write button + # TODO view raw file + # with open(f'content/projects/{name}', 'w') as fp: + # fp.write(content) + # print(f'done {title}.md') + for code in data['code']: + if 'link' in code: + continue + name = code['name'] + desc = code['desc'] + with open(f'content/projects/{name}.md', 'w') as f: + f.write(f'---\ntitle: {name}\ndescription: {desc}\n---\n') + url = f'https://raw.githubusercontent.com/edvb/{name}/master/README.md' + if name == 'tisp': + url = 'https://raw.githubusercontent.com/edvb/tisp/master/doc/tisp.1.md' + with urllib.request.urlopen(url) as response, open(f'content/projects/{name}.md', 'ab') as f: + for chunk in iter(lambda: response.read(1), ''): + if chunk == b'': + break + response.seek(0) + url = f'https://raw.githubusercontent.com/edvb/{name}/master/' + response.read() + with urllib.request.urlopen(url) as response: + shutil.copyfileobj(response, f) + if chunk == b'\n': + break + shutil.copyfileobj(response, f) + +with open('data/photos.yaml') as d: + data = yaml.load(d, Loader=yaml.FullLoader) + for code in data['photos']: + title = code['name'] + name = title.replace(' ', '-') + with open(f'content/photos/{name}.md', 'w') as f: + f.write(f'---\ntitle: {title}\n---\n') + f.write(f'{{{{< photos limit="999" dir="{title}">}}}} ') + # print(f'done {name}.md')