From 23e57d08c2408944f657c4e3493078af963ccb63 Mon Sep 17 00:00:00 2001 From: cellarspoon Date: Wed, 15 Dec 2021 11:43:12 +0100 Subject: [PATCH] centralise config in scripts --- lumbung-calendar-prototype/event_feed.py | 6 +++++- lumbung-hashtag-bot/publish_hashtags.py | 27 ++++++++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/lumbung-calendar-prototype/event_feed.py b/lumbung-calendar-prototype/event_feed.py index a3c7a82..9ac552e 100644 --- a/lumbung-calendar-prototype/event_feed.py +++ b/lumbung-calendar-prototype/event_feed.py @@ -15,7 +15,11 @@ from ics import Calendar from natural import date from slugify import slugify -from event_feed_config import calendar_url, output_dir +# a publicly accessible ICS calendar +calendar_url = os.environ.get("CALENDAR_URL", "") + +# your Hugo content directory +output_dir = os.environ.get("OUTPUT_DIR", "") cal = Calendar(requests.get(calendar_url).text) diff --git a/lumbung-hashtag-bot/publish_hashtags.py b/lumbung-hashtag-bot/publish_hashtags.py index 77bf58c..2bd8eb4 100644 --- a/lumbung-hashtag-bot/publish_hashtags.py +++ b/lumbung-hashtag-bot/publish_hashtags.py @@ -11,18 +11,33 @@ import jinja2 import requests from mastodon import Mastodon -import config_hashtag_bot +# Which instance to login to +instance = "https://social.lumbung.space" + +# n.b. if it is the first time you use this script +# You need to register the app: +# https://mastodonpy.readthedocs.io/en/stable/#module-mastodon + +# Login credentials for bot account +email = "" +password = "" + +# Which hashtags to publish +hashtags = ["jalansesama"] + +# your Hugo content directory +output_dir = os.environ.get("OUTPUT_DIR", "path/to/hugo/content") def login_mastodon_bot(): mastodon = Mastodon( client_id="publishbot_clientcred.secret", - api_base_url=config_hashtag_bot.instance, + api_base_url=instance, ) mastodon.log_in( - config_hashtag_bot.email, - config_hashtag_bot.password, + email, + password, to_file="publishbot_usercred.secret", scopes=["read"], ) @@ -92,7 +107,7 @@ def filter_mastodon_urls(content): mastodon = login_mastodon_bot() -output_dir = config_hashtag_bot.output_dir +output_dir = output_dir env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.curdir)) @@ -107,7 +122,7 @@ if not os.path.exists(output_dir): os.mkdir(output_dir) -for hashtag in config_hashtag_bot.hashtags: +for hashtag in hashtags: hashtag_dir = os.path.join(output_dir, hashtag) if not os.path.exists(hashtag_dir):