Compare commits

...

3 Commits

Author SHA1 Message Date
shibao fb6b67deab add ipfs link support
continuous-integration/drone/push Build is passing Details
2023-09-18 19:40:10 -04:00
shibao 44575f17b1 ignore venv 2023-09-18 19:28:29 -04:00
shibao 8186ed8766 upgrade to python 3.11.5 2023-09-18 17:05:38 -04:00
6 changed files with 30 additions and 10 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
crontab
env/

View File

@ -1 +1 @@
python 3.11.1
python 3.11.5

View File

@ -1,4 +1,4 @@
FROM python:3.11.1-alpine3.17
FROM python:3.11.5-alpine
WORKDIR /usr/src/app
COPY . .

View File

@ -1 +1 @@
0 * * * * cd /usr/src/app && /usr/local/bin/python misskey-szuru-bot.py --instance misskey.io --booru szurubooru.com --username my-username --apiKey my-api-key --token token >/proc/1/fd/1 2>&1
0 * * * * cd /usr/src/app && /usr/local/bin/python misskey_szuru_bot.py --instance misskey.io --booru szurubooru.com --username my-username --api-key my-api-key --token token --ipfs /dns/ipfs.bubbletea.dev/tcp/443/https --ipfs-username=api-username --ipfs-password=api-password >/proc/1/fd/1 2>&1

View File

@ -1,10 +1,14 @@
#!/usr/bin/python3
"""Bot that posts a link to a random szurubooru image"""
import argparse
import pyszuru
import requests
import random
import requests
import ipfshttpclient
from misskey import Misskey
from misskey import NoteVisibility
import pyszuru
# arguments
parser = argparse.ArgumentParser(prog='misskey-szuru-bot',
@ -18,13 +22,19 @@ 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,
parser.add_argument('-a', '--api-key', metavar='api_key', type=str,
help='API key for szurubooru account', required=True)
parser.add_argument('--ipfs', metavar='ipfs', type=str,
help='connection string for an ipfs instance, like /dns/ipfs-api.example.com/tcp/443/https')
parser.add_argument('--ipfs-username', metavar='ipfs_username', type=str,
help='username to connect to ipfs instance')
parser.add_argument('--ipfs-password', metavar='ipfs_password', type=str,
help='username to connect to ipfs instance')
args = parser.parse_args()
# get truly random post
booru = pyszuru.API(f"https://{args.booru}", username=args.username, token=args.apiKey)
booru = pyszuru.API(f"https://{args.booru}", username=args.username, token=args.api_key)
highest_post = next(booru.search_post("sort:id", page_size=1))
post = booru.getPost(random.randint(0, highest_post.id_))
@ -32,6 +42,14 @@ post = booru.getPost(random.randint(0, highest_post.id_))
text = f"link: {post.content}"
if post.safety == "unsafe":
text += " (nsfw)"
# get ipfs hash if ipfs is available
if args.ipfs is not None:
with ipfshttpclient.connect(args.ipfs, auth=(args.ipfs_username, args.ipfs_password)) as client:
r = requests.get(post.content, allow_redirects=True, timeout=60)
FILE_HASH = client.add_bytes(r.content)
text += f"\nipfs: https://ipfs.bubbletea.dev/ipfs/{FILE_HASH}"
text += f"\nsource: https://{args.booru}/post/{post.id_}"
# post a note :D

View File

@ -1,3 +1,4 @@
Misskey.py
requests
pyszuru
ipfshttpclient==0.8.0a2
Misskey.py==4.1.0
pyszuru==0.3.1
Requests==2.31.0