From cf95d377302fa7c60effce43e3675fd6c83418b7 Mon Sep 17 00:00:00 2001 From: Someone Date: Fri, 19 Jun 2020 01:32:13 +0200 Subject: [PATCH] [cron] intern.fsinf.at - Termin-reminder + FSS-TOPs-Info. --- mw_intern/.gitignore | 2 ++ mw_intern/config.py.example | 19 +++++++++++++ mw_intern/fss_tops.py | 40 +++++++++++++++++++++++++++ mw_intern/termin_reminder.py | 52 ++++++++++++++++++++++++++++++++++++ 4 files changed, 113 insertions(+) create mode 100644 mw_intern/.gitignore create mode 100644 mw_intern/config.py.example create mode 100755 mw_intern/fss_tops.py create mode 100755 mw_intern/termin_reminder.py diff --git a/mw_intern/.gitignore b/mw_intern/.gitignore new file mode 100644 index 0000000..bbc97f1 --- /dev/null +++ b/mw_intern/.gitignore @@ -0,0 +1,2 @@ +config.py +data/** diff --git a/mw_intern/config.py.example b/mw_intern/config.py.example new file mode 100644 index 0000000..d3afa0a --- /dev/null +++ b/mw_intern/config.py.example @@ -0,0 +1,19 @@ +# +# Someone's Mattermost scripts. +# Copyright (c) 2016-2020 by Someone (aka. Jan Vales ) +# published under MIT-License +# +# Example config file. +# mv to config.py.examle config.py + edit. +# + +# Mediawiki settings +mw_user = "..." +mw_user_pw = "..." +mw_name = "..." + +# Mattermost settings +mm_api_url = "..." +mm_user = "..." +mm_user_pw = "..." + diff --git a/mw_intern/fss_tops.py b/mw_intern/fss_tops.py new file mode 100755 index 0000000..215c1d6 --- /dev/null +++ b/mw_intern/fss_tops.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +# Someone's Mattermost scripts. +# Copyright (c) 2016-2020 by Someone (aka. Jan Vales ) +# published under MIT-License +# + +import pprint +import re +from inspect import cleandoc + +import mwclient +import mattermost + +import config + + +rex_wtops = re.compile(r"^={1,3}[^=].*$", re.IGNORECASE|re.MULTILINE) + + +def process_wiki(mws, mm): + # notify of upcomming events. (up to: now +- 30 min) + page = mws.Pages["TOPs_der_kommenden_Fachschaftssitzung"] + pprint.pprint(page) + found = [re.sub(r"\s*=+\s*$", "", "+ ".join([re.sub(r"^(=+)\s*", r"\g<1>+ ", x).split("+ ", 1)[0].replace("=", " "), re.sub(r"^(=+)\s*", r"\g<1>+ ", x).split("+ ", 1)[1]])) for x in re.findall(rex_wtops, page.text())] + + msg = "``BOT-AUTODELETE-SLOW``\n### :warning: ``Upcoming FSS-TOPs`` :warning:\n@channel Zwecks Hut-Top-Minimierung, trage bitte deine TOPs asap ein. :)!\n" + msg += ":arrow_right: https://intern.fsinf.at/wiki/TOPs_der_kommenden_Fachschaftssitzung\n\n----\n" + msg += cleandoc("\n".join(found)) + print("Posting to channel:" +str(mm.create_post(config.mm_chanid, msg))) + + +if __name__ == "__main__": + mws = mwclient.Site(config.mw_name, path="/") + mws.login(config.mw_user, config.mw_user_pw) + mm = mattermost.MMApi(config.mm_api_url) + mm.login(config.mm_user, config.mm_user_pw) + + process_wiki(mws, mm) + + mm.logout() diff --git a/mw_intern/termin_reminder.py b/mw_intern/termin_reminder.py new file mode 100755 index 0000000..28888cc --- /dev/null +++ b/mw_intern/termin_reminder.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 +# Someone's Mattermost scripts. +# Copyright (c) 2016-2020 by Someone (aka. Jan Vales ) +# published under MIT-License +# + +import datetime +import pprint +import re + +import mwclient +import mattermost + +import config + + +REXwreminder_line = re.compile(r"^\s*(\{\{mm-reminder\|[^\|\}]+\|.*\}\}.*)$", re.IGNORECASE|re.MULTILINE) +REXwreminder_data = re.compile(r"^^\s*\{\{mm-reminder\|([^\|\}]+)\|?(.*\}\}.*)$", re.IGNORECASE) + + +def processData(mws, mm, datasource, matchdata): + match = re.match(REXwreminder_data, matchdata) + + timediff = datetime.datetime.now() - datetime.datetime.strptime(match.group(1), "%Y-%m-%d %H:%M") + if abs(timediff.total_seconds()) > 1800.0: + print("outside of 1800 sec.") + return + + msg = "``BOT-AUTODELETE-SLOW`` Termin-Reminder source: "+datasource+"\n### ``"+(match.group(2).replace("}}", "``", 1)) + print("Posting to channel:" +str(mm.create_post(config.mm_chanid, msg))) + + +def processWiki(mws, mm): + # notify of upcomming events. (up to: now +- 30 min) + page = mws.Pages["TOPs_der_kommenden_Fachschaftssitzung"] + pprint.pprint(page) + for t in re.findall(REXwreminder_line, page.text()): + try: + processData(mws, mm, "https://"+config.mw_name+"/wiki/TOPs_der_kommenden_Fachschaftssitzung", t) + except: + pass + + +if __name__ == "__main__": + mws = mwclient.Site(config.mw_name, path="/") + mws.login(config.mw_user, config.mw_user_pw) + mm = mattermost.MMApi(config.mm_api_url) + mm.login(config.mm_user, config.mm_user_pw) + + processWiki(mws, mm) + + mm.logout() -- 2.43.0