Compare commits
No commits in common. "fb6b67deabd56b1df9b4b4f0ed97c10db4a6b37a" and "f562e264e23229fab434d32a9042b99ca6326916" have entirely different histories.
fb6b67deab
...
f562e264e2
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1 @@
|
|||||||
crontab
|
crontab
|
||||||
env/
|
|
||||||
|
@ -1 +1 @@
|
|||||||
python 3.11.5
|
python 3.11.1
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
FROM python:3.11.5-alpine
|
FROM python:3.11.1-alpine3.17
|
||||||
|
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
COPY . .
|
COPY . .
|
||||||
|
@ -1 +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
|
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
|
||||||
|
@ -1,14 +1,10 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
"""Bot that posts a link to a random szurubooru image"""
|
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import random
|
import pyszuru
|
||||||
import requests
|
import requests
|
||||||
import ipfshttpclient
|
import random
|
||||||
from misskey import Misskey
|
from misskey import Misskey
|
||||||
from misskey import NoteVisibility
|
from misskey import NoteVisibility
|
||||||
import pyszuru
|
|
||||||
|
|
||||||
# arguments
|
# arguments
|
||||||
parser = argparse.ArgumentParser(prog='misskey-szuru-bot',
|
parser = argparse.ArgumentParser(prog='misskey-szuru-bot',
|
||||||
@ -22,19 +18,13 @@ parser.add_argument('-b', '--booru', metavar='booru', type=str,
|
|||||||
help='Domain of szurubooru instance to query i.e: szurubooru.com', required=True)
|
help='Domain of szurubooru instance to query i.e: szurubooru.com', required=True)
|
||||||
parser.add_argument('-u', '--username', metavar='username', type=str,
|
parser.add_argument('-u', '--username', metavar='username', type=str,
|
||||||
help='Username for szurubooru account', required=True)
|
help='Username for szurubooru account', required=True)
|
||||||
parser.add_argument('-a', '--api-key', metavar='api_key', type=str,
|
parser.add_argument('-a', '--apiKey', metavar='apiKey', type=str,
|
||||||
help='API key for szurubooru account', required=True)
|
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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# get truly random post
|
# get truly random post
|
||||||
booru = pyszuru.API(f"https://{args.booru}", username=args.username, token=args.api_key)
|
booru = pyszuru.API(f"https://{args.booru}", username=args.username, token=args.apiKey)
|
||||||
highest_post = next(booru.search_post("sort:id", page_size=1))
|
highest_post = next(booru.search_post("sort:id", page_size=1))
|
||||||
post = booru.getPost(random.randint(0, highest_post.id_))
|
post = booru.getPost(random.randint(0, highest_post.id_))
|
||||||
|
|
||||||
@ -42,14 +32,6 @@ post = booru.getPost(random.randint(0, highest_post.id_))
|
|||||||
text = f"link: {post.content}"
|
text = f"link: {post.content}"
|
||||||
if post.safety == "unsafe":
|
if post.safety == "unsafe":
|
||||||
text += " (nsfw)"
|
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_}"
|
text += f"\nsource: https://{args.booru}/post/{post.id_}"
|
||||||
|
|
||||||
# post a note :D
|
# post a note :D
|
@ -1,4 +1,3 @@
|
|||||||
ipfshttpclient==0.8.0a2
|
Misskey.py
|
||||||
Misskey.py==4.1.0
|
requests
|
||||||
pyszuru==0.3.1
|
pyszuru
|
||||||
Requests==2.31.0
|
|
||||||
|
Loading…
Reference in New Issue
Block a user