initial commit

This commit is contained in:
shibao 2022-12-15 19:31:12 -05:00
commit e4e504f713
7 changed files with 55 additions and 0 deletions

3
.dockerignore Normal file
View File

@ -0,0 +1,3 @@
.gitignore
crontab
crontab.example

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
crontab

1
.tool-versions Normal file
View File

@ -0,0 +1 @@
python 3.11.1

9
Dockerfile Normal file
View File

@ -0,0 +1,9 @@
FROM python:3.11.1-alpine3.17
COPY . .
RUN pip install -r requirements.txt
RUN crontab crontab
CMD ["crond", "-f"]

1
crontab.example Normal file
View File

@ -0,0 +1 @@
0 * * * * python misskey-szuru-bot.py --instance misskey.io --token token_here --booru szurubooru.com --username my-username --apiKey szuru-login-token --query "sort:random"

37
misskey-szuru-bot.py Normal file
View File

@ -0,0 +1,37 @@
#!/usr/bin/python3
import argparse
import pyszuru
import requests
from misskey import Misskey
# arguments
parser = argparse.ArgumentParser(prog='misskey-szuru-bot',
description='Bot that posts a link to a random szurubooru image')
parser.add_argument('-i', '--instance', metavar='instance', type=str,
help='Domain of misskey instance i.e: misskey.io', required=True)
parser.add_argument('-t', '--token', metavar='token', type=str,
help='Token used for posting to misskey instance', required=True)
parser.add_argument('-b', '--booru', metavar='booru', type=str,
help='Domain of szurubooru instance to query i.e: szurubooru.com', required=True)
parser.add_argument('-u', '--username', metavar='username', type=str,
help='Username for szurubooru account', required=True)
parser.add_argument('-a', '--apiKey', metavar='apiKey', type=str,
help='API key for szurubooru account', required=True)
parser.add_argument('-q', '--query', metavar='query', type=str,
help='Query to search szurubooru', default="sort:random")
args = parser.parse_args()
# get post
booru = pyszuru.API(f"https://{args.booru}", username=args.username, token=args.apiKey)
post = next(booru.search_post(args.query))
# compose note
text = f"link: {post.content}"
if post.safety == "unsafe":
text += " (nsfw)"
text += f"source: https://{args.booru}/post/{post.id_}"
# post a note :D
Misskey(args.instance, i=args.token).notes_create(text=text)

3
requirements.txt Normal file
View File

@ -0,0 +1,3 @@
Misskey.py
requests
pyszuru