home · login to get plonkin'

ehnotif v1.1

@futanari.observer · 1mo ago · python · 104 loc · raw · 0 comments

1# dependencies: xmltodict2# setup: echo -n "0" > lastnotif; put your discord webhook url in webhookurl3import requests4import xmltodict5from time import sleep6from datetime import datetime, timezone7from collections import defaultdict89# put the tags you wanna watch below10WATCHED = [11    {12        "language": {"speechless", "english"},13    },14    {15        "artist": {16            "acbins", "agagaga", "aimaitei umami", "airandou", "akiamare", "alp", "aomushi",17            "binto",18            "dakkoku jiro",19            "eigetu",20            "frogsnake",21            "gennsui",22            "hanpatsu zokusei",23            "itami",24            "jairou",25            "kakuninii", "kamata", "kamotama", "kataokasan", "katou jun", "kawakami kou", "koyama shigeru",26            "lbl", "lemon snail",27            "magifuro konnyaku",28            "mmchair", "momomo", "muneshiro",29            "nakani", "noname",30            "okuva",31            "poncocchan",32            "rabu",33            "sakai", "sella", "shakekare", "sumiyao",34            "tototo", "try",35            "wagashi",36            "yassy", "yoshiie",37        },38        "group": {"aimaitei", "contamination", "gyuumagyuuma", "kemomimi eki", "otonano omochiya", "yuruyakatou"}39    }40]414243FJORDED = {"lolicon", "shotacon", "toddlercon", "abortion", "bestiality"}4445def main():46    res = xmltodict.parse(requests.get("https://xml.e-hentai.org/ehg.xml").text, cdata_separator="\n")47    entries = res["feed"]["entry"]4849    for e in entries:50        e["updated"] = datetime.fromisoformat(e["updated"])5152    with open("lastnotif", "r+") as f:53        lastnotif = datetime.fromtimestamp(int(f.read().strip()), tz=timezone.utc)54        f.seek(0)55        f.write(str(int(entries[0]["updated"].timestamp())))56        f.truncate()5758    with open("webhook", "r") as f:59        webhookurl = f.read().strip()6061    for e in entries:62        if e["updated"] > lastnotif:63            content = e["content"]["div"]["p"][1]["#text"]64            tags_text, desc_text = content.split("\n", maxsplit=1)65            tags = defaultdict(set)66            for nstag in tags_text.removeprefix("Tags: ").split(", "):67                if ":" not in nstag:68                    tags["temp"].add(nstag)69                else:70                    ns, tag = nstag.split(":")71                    tags[ns].add(tag)7273            fail = False74            for condition in WATCHED:75                if not any(tags[ns] & required for ns, required in condition.items()):76                    fail = True77                    break78            if fail: continue7980            tags_text = "\n".join(ns + ": " + " ".join(f"`{tag}`" for tag in sorted(t)) for ns, t in tags.items())81            embed = {82                "title": e["title"][:256],83                "url": e["link"]["@href"],84                "description": tags_text[:4096], # desc_text.removeprefix("Description: ") + "\n\n" +85                "color": 0x000000,86            }8788            fjorded = any(FJORDED & t for t in tags.values())89            if not fjorded: # yeah let's *try* not getting banned from discord90                embed["thumbnail"] = {"url": e["content"]["div"]["img"]["@src"]}9192            print(embed)93            print(requests.post(webhookurl, json={"embeds": [embed]}))94            sleep(1)9596if __name__ == "__main__":97    try:98        main()99    except Exception as e:100        print(e)101        with open("webhook", "r") as f:102            webhookurl = f.read().strip()103        requests.post(webhookurl, json={"content": f"{e.__class__.__name__}: {str(e)}"[:2000]})104

login to post a comment