From 581edf5fffc027926c74f19b3470ce12b9ac0ee2 Mon Sep 17 00:00:00 2001 From: Pieter De Praetere Date: Sun, 3 Jan 2021 17:55:37 +0100 Subject: [PATCH] Scripts to create themes --- .../create_skeleton_for_accepted_stands.py | 3 +- scripts/create_themes.py | 67 +++++++++++++++++++ scripts/fetch_stands_code.py | 55 +++++++++++++++ 3 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 scripts/create_themes.py create mode 100644 scripts/fetch_stands_code.py diff --git a/scripts/create_skeleton_for_accepted_stands.py b/scripts/create_skeleton_for_accepted_stands.py index 62ba07c..e1ace44 100644 --- a/scripts/create_skeleton_for_accepted_stands.py +++ b/scripts/create_skeleton_for_accepted_stands.py @@ -1,10 +1,11 @@ +#!/usr/bin/env python3 import requests from os import mkdir from os.path import exists, isfile, isdir def fetch(): - result = requests.get('http://stands.fosdem.org/submission/api/accepted') + result = requests.get('https://stands.fosdem.org/submission/api/accepted') result.raise_for_status() return result.json() diff --git a/scripts/create_themes.py b/scripts/create_themes.py new file mode 100644 index 0000000..dbaa79e --- /dev/null +++ b/scripts/create_themes.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 +import requests +from os import mkdir +from os.path import exists, isfile, isdir +import re + + +def fetch(): + result = requests.get('https://stands.fosdem.org/submission/api/themes') + result.raise_for_status() + return result.json() + + +def slug(name): + illegal_r = re.compile('[^A-Za-z0-9_-]') + return illegal_r.sub('-', name.lower()) + + +def create_skeleton(theme_o): + path = '../content/themes/{0}'.format(slug(theme_o['theme'])) + static_path = '../static/themes/{0}'.format(slug(theme_o['theme'])) + if not exists(path): + mkdir(path) + if not exists(static_path): + mkdir(static_path) + _index = """--- +title: {0} +description: | + {1} +logo: img/lib/material-icons/{2}.svg +--- +""".format( + theme_o['theme'], + theme_o['description'], + slug(theme_o['theme']) +) + if not exists('{0}/_index.md'.format(path)): + with open('{0}/_index.md'.format(path), 'w') as fh: + fh.write(_index) + + +def main(): + print('Fetching list of themes ... ', end=None) + try: + themes = fetch() + except Exception as e: + print('[FAILED]') + print('\t\t {0}'.format(e)) + return(10) + else: + print('[OK]') + for theme in themes: + print('Creating skeleton for {0} ... '.format(theme['theme']), end=None) + try: + create_skeleton(theme) + except Exception as e: + print('[FAILED]') + print('\t\t {0}'.format(e)) + else: + print('[OK]') + return 0 + + + +if __name__ == '__main__': + exit(main()) + diff --git a/scripts/fetch_stands_code.py b/scripts/fetch_stands_code.py new file mode 100644 index 0000000..553b710 --- /dev/null +++ b/scripts/fetch_stands_code.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 +import requests +from os import mkdir +from os.path import exists, isfile, isdir + + +def fetch(): + result = requests.get('http://localhost:8000/submission/api/accepted') + result.raise_for_status() + return result.json() + + +def create_skeleton(stand_o): + path = '../content/stands/{0}'.format(stand_o['submission']['project']['name'].lower()) + static_path = '../static/stands/{0}'.format(stand_o['submission']['project']['name'].lower()) + if exists('{0}/.git'.format(path)): + # Pull + cmd = 'git pull origin master' + else: + # Clone + cmd = 'git clone {0}'.format(stand_o['submission']['digital_edition']['stand_website_code']) + if exists('{0}/.git'.format(static_path)): + # Pull + static_cmd = 'git pull origin master' + else: + # Clone + static_cmd = 'git clone {0}'.format(stand_o['submission']['digital_edition']['stand_website_static']) + + +def main(): + print('Fetching list of accepted stands ... ', end=None) + try: + accepted_stands = fetch() + except Exception as e: + print('[FAILED]') + print('\t\t {0}'.format(e)) + return(10) + else: + print('[OK]') + for stand in accepted_stands: + print('Pulling code for {0} ... '.format(stand['submission']['project']['name']), end=None) + try: + create_skeleton(stand) + except Exception as e: + print('[FAILED]') + print('\t\t {0}'.format(e)) + else: + print('[OK]') + return 0 + + + +if __name__ == '__main__': + exit(main()) + -- 2.30.2