diff --git a/bytebot_config.py.example b/bytebot_config.py.example new file mode 100644 index 0000000..8efddf9 --- /dev/null +++ b/bytebot_config.py.example @@ -0,0 +1,106 @@ +import os + +BYTEBOT_STATUS_URL = 'http://status.bytespeicher.org/status.json' + +BYTEBOT_HTTP_TIMEOUT = 3 +BYTEBOT_HTTP_MAXSIZE = 1024 * 1024 * 10 + +BYTEBOT_PLUGIN_CONFIG = { + 'rss': [ + { + 'name': 'Wiki', + 'url': 'http://www.technikkultur-erfurt.de/feed.php', + 'cache': '/tmp/feed_wiki.cache', + 'type': 'dokuwiki', + }, + { + 'name': 'Website', + 'url': 'https://bytespeicher.org/feed/', + 'cache': '/tmp/feed_website.cache', + 'type': 'wordpress', + }, + { + 'name': 'BytebotCommits', + 'url': 'https://github.com/Bytespeicher/Bytebot/commits/master.atom', + 'cache': '/tmp/feed_bytebot.cache', + 'type': 'github', + }, + { + 'name': 'Redmine', + 'url': 'http://redmine.bytespeicher.org/issues.atom', + 'cache': '/tmp/feed_rm_bytespeicher.cache', + 'type': 'redmine', + }, + { + 'name': 'SpacestatusCommits', + 'url': 'https://github.com/Bytespeicher/space-status/commits/master.atom', + 'cache': '/tmp/feed_spacestatus.cache', + 'type': 'github' + }, + ], + 'dates': { + 'url': 'http://www.google.com/calendar/ical/2eskb61g20prl65k2qd01uktis%40group.calendar.google.com/public/basic.ics', + 'timedelta': 21 + }, + 'messagelogger': { + 'file': '/tmp/irc.log' + }, + 'usercount': { + 'file': '/tmp/irc_user.log' + }, + 'autoop': { + 'name': { + '#channelname': [ + 'username', + ], + }, + 'hostmask': { + '#channelname': [ + 'username!~user@example.com' + ], + } + }, + 'spacestatus': { + 'url': 'http://status.bytespeicher.org/status.json' + }, + 'ircquestions': { + 'location': 'http://technikkultur-erfurt.de/bytespeicher:anfahrt', + 'dates': 'http://technikkultur-erfurt.de/bytespeicher:veranstaltungen', + 'versorgung': 'http://technikkultur-erfurt.de/bytespeicher:versorgung', + }, + 'shorturl': { + 'shortener': 'krzus', + 'api_key': 'thiswoudbeyourapikey', + 'clarifai_app_id': 'yourappid', + 'clarifai_app_secret': 'yourappsecret', + }, + 'parking': { + 'url': 'parking_url', + }, + 'mensa': { + 'canteen': 148, + }, + 'fuel': { + 'apikey': 'thiswoudbeyourapikey', + 'lat': '50.9827792', + 'lng': '11.0394426', + 'rad': '10', + }, + 'cccongress': { + 'url': 'https://events.ccc.de/congress/YEAR/Fahrplan/schedule.json', + 'cache': '/tmp/cccongress.cache', + 'announce_minutes': 15, + }, + 'weather': { + 'api_key': 'your_apikey', + 'url': 'http://api.openweathermap.org/data/2.5/weather?units=metric&q=', + 'location': 'city,countrycode' + }, + 'wikipedia': { + 'url': 'https://de.wikipedia.org/w/api.php?&action=query&format=json&prop=extracts&exintro=&explaintext=&titles=', + 'length_of_abstract': 400 + }, + 'betterplace': { + 'id': 24759, + }, +} diff --git a/plugins/betterplace.py b/plugins/betterplace.py new file mode 100644 index 0000000..9a258ed --- /dev/null +++ b/plugins/betterplace.py @@ -0,0 +1,53 @@ +from irc3.plugins.command import command + +from bytebot_config import BYTEBOT_PLUGIN_CONFIG +from irc3 import asyncio +import aiohttp +import json + + +@command(permission="view") +@asyncio.coroutine +def betterplace(bot, mask, target, args): + """Show the current betterplace projects + + %%betterplace + """ + config = BYTEBOT_PLUGIN_CONFIG['betterplace'] + + if config['id'] == "betterplace_id": + return "I don't have your betterplace id!" + + bot.privmsg(target, 'betterplace projects:') + + try: + url = "https://api.betterplace.org/de/api_v4/organisations/" + \ + str(config['id']) + \ + "/projects.json" + + with aiohttp.Timeout(10): + with aiohttp.ClientSession(loop=bot.loop) as session: + resp = yield from session.get(url) + if resp.status != 200: + bot.privmsg( + target, "Error while retrieving " + __name__ + " data") + raise Exception() + r = yield from resp.read() + + projects = json.loads(r.decode('utf-8')) + + for d in projects["data"]: + if(d["closed_at"] is None): + bot.privmsg(target, + " {name:35}" + + " {got:3}€ von {want:3}€ gespendet".format( + name=d["title"], + got=int( + d["donated_amount_in_cents"]) / 100, + want=int(d["donated_amount_in_cents"] + + d["open_amount_in_cents"]) / 100 + )) + + except KeyError: + bot.privmsg(target, "Error while retrieving " + __name__ + " data") + raise Exception()