a Google Apps Script to update your subreddit sidebar
Hi, I'm a Google Apps Script for updating your subreddit's sidebar periodically. Currently, I only know how to update a schedule from a Google Calendar, but you can teach me new tricks.
Here's how it works:
The script signs into a configured mod account using OAuth2. It fetches a wiki
page in your subreddit called "sidebar_template". The configured Google
Calendar is then read: events between the start of today and a configurable
DAY_RANGE
days ahead are added to a markdown table. If the sidebar grows past
reddit's limit, the script stops with however many lines will fit. Finally, the
wiki page "config/sidebar" (your subreddit sidebar) is updated by taking
"sidebar_template" and replacing the text {{SCHEDULE}}
with the schedule
table.
To use it, you'll need:
{{SCHEDULE}}
in place where you'd like it to be inserted){{SCHEDULE}}
where you wish for the schedule to be.You can then give the script a test run by clicking "Run -> updateSchedule" in the menu on Google Apps Script. Then check the sidebar edit history for your subreddit (e.g. http://www.reddit.com/r/IAmA/wiki/revisions/config/sidebar) to verify what the script changed.
Finally, if everything seems to be working properly, you can turn on periodic runs. In the Google Apps Script page menu, click "Resources -> Current project's triggers". Then choose to add a new trigger. You'll be presented with a form that should default to hourly runs. I'd also recommend clicking the "notifications" button and setting it up to email you immediately if the script fails for some reason.
Google Apps Script lets you configure the timezone the script treats dates with in File -> Project properties.
If there's no change to the sidebar during a run, reddit won't add an entry to the wiki history.
Google Apps Script has quotas for various actions. Running the script hourly (or faster) should stay well clear of those limits, but please be conscientious of Google's and reddits servers and try to keep them in mind.