forked from lilith/yuri
36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
import anyio
|
|
from mastodon import Mastodon
|
|
from pygelbooru import Gelbooru
|
|
from dotenv import dotenv_values
|
|
from urllib.request import Request, urlopen
|
|
|
|
config = dotenv_values(".env")
|
|
gelbooru = Gelbooru(config["GELBOORU_API_KEY"], config["GELBOORU_API_UID"])
|
|
|
|
async def main():
|
|
masto = Mastodon(api_base_url = config["PLEROMA_INSTANCE"], access_token = config["PLEROMA_ACCESS_TOKEN"], feature_set = "pleroma")
|
|
|
|
try:
|
|
posts = await gelbooru.search_posts(tags=["sort:random", "rating:s", "yuri", "sisters"], exclude_tags=["ai_generated", "1boy"])
|
|
result = posts[0]
|
|
|
|
req = Request(url=result.file_url, headers={"User-Agent": "Mozilla/5.0"})
|
|
data = urlopen(req).read()
|
|
|
|
file = open("/tmp/" + result.filename, "wb")
|
|
file.write(data)
|
|
file.close()
|
|
|
|
tags = " ".join(result.tags)
|
|
medias = masto.media_post("/tmp/" + result.filename, description=tags)
|
|
|
|
source = ""
|
|
if result.source != None:
|
|
source = "[source](" + result.source + ")"
|
|
|
|
masto.status_post(source, content_type="text/markdown", media_ids=medias)
|
|
except Exception:
|
|
import traceback
|
|
masto.status_post("@ashley@incest.world\n\n" + traceback.format_exc(), visibility="direct", spoiler_text="error!!!")
|
|
|
|
anyio.run(main)
|