Skip to content
Snippets Groups Projects
Commit 81bcf604 authored by dnns01's avatar dnns01
Browse files

Add armin command, that roughly sums up the number of positive covid cases...

Add armin command, that roughly sums up the number of positive covid cases reported since Armin got elected
parent 6ab5d0be
Branches
No related tags found
No related merge requests found
from datetime import datetime, timedelta
import requests
from twitchio.ext import commands
@commands.core.cog(name="ArminCog")
class Armin:
def __init__(self, bot):
self.bot = bot
@commands.command(name="armin")
async def cmd_armin(self, ctx):
url = "https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_COVID19/FeatureServer/0/query?where=Meldedatum+%3E%3D+TIMESTAMP+%272021-01-16%27+AND+NeuerFall+in+%281%2C+0%29&objectIds=&time=&resultType=standard&outFields=AnzahlFall%2CMeldeDatum%2C+NeuerFall&returnIdsOnly=false&returnUniqueIdsOnly=false&returnCountOnly=false&returnDistinctValues=false&cacheHint=false&orderByFields=MeldeDatum&groupByFieldsForStatistics=AnzahlFall%2CMeldeDatum%2C+NeuerFall&outStatistics=%5B%7B%22statisticType%22%3A%22sum%22%2C%22onStatisticField%22%3A%22AnzahlFall%22%2C%22outStatisticFieldName%22%3A%22cases%22%7D%5D&having=&resultOffset=&resultRecordCount=&sqlFormat=none&f=pjson&token="
response = requests.get(url)
data = response.json()
cases_per_day = {}
yesterday = (datetime.now() - timedelta(days=1)).strftime("%Y-%m-%d")
count = 0
for feature in data["features"]:
melde_datum = datetime.fromtimestamp(feature["attributes"]['MeldeDatum'] / 1000)
neuer_fall = feature["attributes"]["NeuerFall"]
cases = feature["attributes"]["cases"]
if yesterday == melde_datum.strftime("%Y-%m-%d") and neuer_fall == 0:
continue
if cases_per_day.get(melde_datum) is None:
cases_per_day[melde_datum] = cases
else:
cases_per_day[melde_datum] = cases + cases_per_day.get(melde_datum)
for date, case in cases_per_day.items():
count += case
await ctx.send(
f"Es wurden schon {format(count, ',').replace(',', '.')} (+-100%) Neuinfektionen gemeldet, seit Kanzler-Elect Armin an der Macht ist. So klappt es nicht! strolchSauer")
......@@ -3,16 +3,17 @@ import random
import sqlite3
from abc import ABC
from time import sleep, time
from dotenv import load_dotenv
import requests
from twitchio.dataclasses import Context, Message, Channel
from twitchio.ext import commands
from armin import Armin
from dotenv import load_dotenv
from giveaway_cog import GiveawayGog
from klassenbuch_cog import KlassenbuchCog
from link_protection import LinkProtection
from spotify_cog import SpotifyCog
from twitchio.dataclasses import Context, Message, Channel
from twitchio.ext import commands
from vote_cog import VoteCog
from link_protection import LinkProtection
import config
load_dotenv()
......@@ -36,6 +37,7 @@ class StrolchiBot(commands.Bot, ABC):
self.add_cog(KlassenbuchCog(self))
self.add_cog(SpotifyCog(self))
self.add_cog(LinkProtection(self))
self.add_cog(Armin(self))
@staticmethod
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment