-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revert #86 , this is not the way to do it.
- Loading branch information
Showing
6 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ django-extensions | |
python-dateutil | ||
freezegun | ||
feedparser | ||
requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from django.core.management.base import NoArgsCommand, CommandError | ||
from django.conf import settings | ||
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist | ||
from django.core.mail import send_mail | ||
from django.template.loader import get_template | ||
from django.template import Context | ||
from cal.models import Event | ||
import datetime, requests | ||
|
||
# TODO: does this handle timezones correctly? | ||
# TODO: send a warning mail to core if the next jour fixe does not have a wiki page | ||
|
||
def get_next_jf(): | ||
when = datetime.date.today() + datetime.timedelta(days = settings.MOS_JF_DAYS_IN_ADVANCE) | ||
try: | ||
# FIXME: django too old, this doesn't work yet: startDate__date = when | ||
return Event.objects.get(category_id = settings.MOS_JF_DB_ID, | ||
startDate__year = when.year, | ||
startDate__month = when.month, | ||
startDate__day = when.day) | ||
except MultipleObjectsReturned as e: | ||
raise e # FIXME: Ehhhhh. Multiple Jour fixes in the calendar for the same date. | ||
except ObjectDoesNotExist: | ||
return None | ||
|
||
def get_wiki_article(article): | ||
query = {"action": "parse", "page": article, "format": "json"} | ||
return requests.get(settings.MEDIAWIKI_API, params = query).json() | ||
|
||
def get_wiki_headlines(article): | ||
article = get_wiki_article(article) | ||
if article.get("error", False): | ||
return {"article_missing": True, "error": True, "headlines": []} | ||
|
||
results = [] | ||
skip = True | ||
for heading in article["parse"]["sections"]: | ||
if heading["toclevel"] == 1: | ||
skip = heading["anchor"] != "Themen" | ||
continue | ||
if skip: | ||
continue | ||
results.append(heading["line"]) | ||
|
||
return {"article_missing": False, "error": len(results) == 0, "headlines": results} | ||
|
||
def mail(template, ctx_vars): | ||
tpl = get_template(template) | ||
ctx = Context(ctx_vars) | ||
msg = tpl.render(ctx) | ||
sub = ''.join(get_template(template + ".subject").render(ctx).splitlines()) | ||
send_mail(sub, msg, | ||
settings.MOS_JF_SENDER, | ||
settings.MOS_JF_RECIPIENTS, | ||
fail_silently=False) | ||
|
||
class Command(NoArgsCommand): | ||
help = 'Send the Jour Fixe reminder email, if a Jour Fixe is in settings.MOS_JF_DAYS_IN_ADVANCE days' | ||
def handle_noargs(self, **options): | ||
next_jf = get_next_jf() | ||
if not next_jf: | ||
return | ||
ctx = { 'jf': next_jf, 'wiki': get_wiki_headlines(next_jf.wikiPage) } | ||
mail("jour_fixe_reminder.mail", ctx) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{% load i18n %}{% language 'de' %}Liebe Leute, | ||
|
||
Am {{ jf.startDate | date:"l" }} den {{ jf.startDate | date:"Y-m-d" }} um {{ jf.startDate | date:"H:i" }} gibt es einen Jour Fixe. | ||
|
||
{% if wiki.article_missing %} | ||
Leider gibt es dazu keinen Wiki-Artikel. Das bedeutet wahrscheinlich, dass der | ||
Jour Fixe ausfällt. Die Deadline für neue Themen ist nämlich vorbei. | ||
{% elif wiki.error %} | ||
Leider hat der Wiki-Artikel das falsche Format und kann nicht geparst werden, | ||
oder es ist ein anderer Fehler beim lesen des Artikels aufgetreten. Wenn das MOS | ||
den Artikel nicht lesen kann, kannst du ihn sicher auch nicht lesen ;) | ||
Du kannst es aber versuchen. | ||
{% else %}Folgende Themen wurden bisher im Wiki eingetragen: | ||
{% for heading in wiki.headlines %} | ||
* {{ heading }}{% if heading == "Thema1 (you)" %} - bitte löscht diese Boilerplate-Themen raus, wenn ihr ein Thema anlegt.{% endif %}{% endfor %} | ||
|
||
Laut einer gottgegebenen Regel müssen Jour-Fixe-Themen mindestens 3 Tage vor dem | ||
Termin eingetragen sein, wenn du also noch Vorschläge hast, bitte nimm sie mit | ||
zum nächsten Jour Fixe. | ||
{% endif %} | ||
Wiki Page: https://metalab.at/wiki/{{ jf.wikiPage }} | ||
|
||
<3 dein MOS{% endlanguage %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{% load i18n %} | ||
{% language 'de' %} | ||
[REMINDER] Jour Fixe am {{ jf.startDate | date:"l, Y-m-d" }} | ||
{% endlanguage %} |