Rewrite from python to bash
parent
8635305740
commit
25cbe41835
@ -1,60 +0,0 @@
|
||||
import requests
|
||||
import sys
|
||||
|
||||
import os.path as op
|
||||
|
||||
TAGS = '1girl reisen_udongein_inaba'
|
||||
|
||||
def main():
|
||||
|
||||
PAGE = 0
|
||||
rejected_once = False
|
||||
|
||||
while True:
|
||||
|
||||
URL = "https://danbooru.donmai.us/posts.json"
|
||||
PARAMS = { 'tags': TAGS,
|
||||
'page': PAGE }
|
||||
|
||||
r = requests.get(url = URL, params = PARAMS)
|
||||
data = r.json()
|
||||
|
||||
# If didn't receive a single entity, we should try again.
|
||||
# If failed another time, shutdown!
|
||||
if data.count == 0:
|
||||
if rejected_once == True:
|
||||
return
|
||||
rejected_once = True
|
||||
continue
|
||||
rejected_once = False
|
||||
|
||||
for entity in data:
|
||||
if entity['rating'] != 's':
|
||||
continue
|
||||
|
||||
file_tags = entity['tag_string']
|
||||
|
||||
# we don't want comics
|
||||
if 'comic' in file_tags:
|
||||
continue
|
||||
|
||||
try:
|
||||
file_url = entity['file_url']
|
||||
except:
|
||||
continue
|
||||
|
||||
# write the art
|
||||
img_data = requests.get(file_url).content
|
||||
with open('source/' + file_url[file_url.rfind("/")+1:], 'wb') as handler:
|
||||
handler.write(img_data)
|
||||
|
||||
# save its url separately into a file
|
||||
with open('urls', 'a', encoding='utf-8') as file:
|
||||
print(file_url, file=file)
|
||||
|
||||
PAGE += 1
|
||||
|
||||
# end while True
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
@ -1,82 +0,0 @@
|
||||
import requests
|
||||
import sys
|
||||
|
||||
import os.path as op
|
||||
from mastodon import Mastodon
|
||||
|
||||
# --------------------------------------------------
|
||||
|
||||
def main():
|
||||
|
||||
mastodon = Mastodon(
|
||||
access_token = 'token.dat',
|
||||
api_base_url = 'https://udongein.xyz/'
|
||||
)
|
||||
|
||||
with open('tags.dat', 'r') as dat:
|
||||
tags = dat.readlines()
|
||||
|
||||
URL = "https://danbooru.donmai.us/posts.json"
|
||||
LIMIT = 10
|
||||
MIN_SCORE = 25
|
||||
SAFETY = 's'
|
||||
TAGS_POST = tags[0].strip()
|
||||
TAGS_FORBID = tags[1].strip().split()
|
||||
TAGS_SENSITIVE = tags[2].strip().split()
|
||||
|
||||
PARAMS = { 'tags': TAGS_POST,
|
||||
'limit': LIMIT,
|
||||
'random': True }
|
||||
|
||||
print('[start] Settings:')
|
||||
print('LIMIT = ' + str(LIMIT) + ' | MIN_SCORE = ' + str(MIN_SCORE) + ' | SAFETY = ' + SAFETY)
|
||||
print('TAGS_POST=' + str(TAGS_POST))
|
||||
print('TAGS_FORBID=' + str(TAGS_FORBID))
|
||||
print('TAGS_SENSITIVE=' + str(TAGS_SENSITIVE) + '\n')
|
||||
|
||||
# --------------------------------------------------
|
||||
|
||||
counter = 1
|
||||
b_search = True
|
||||
while b_search:
|
||||
r = requests.get(url = URL, params = PARAMS)
|
||||
print('[get] Attempt N' + str(counter) + '.')
|
||||
data = r.json()
|
||||
for i in range(0, LIMIT):
|
||||
fileurl = data[i]['file_url']
|
||||
print('url ', fileurl)
|
||||
fileid = data[i]['id']
|
||||
print('id ', fileid)
|
||||
filescore = data[i]['fav_count']
|
||||
print('score ', filescore)
|
||||
filesafe = data[i]['rating']
|
||||
print('rating ', filesafe)
|
||||
filetagstring = data[i]['tag_string']
|
||||
print('tags ', filetagstring)
|
||||
pulledtags = filetagstring.split()
|
||||
|
||||
if (filesafe == SAFETY and filescore >= MIN_SCORE
|
||||
and not set(pulledtags).intersection(TAGS_FORBID)):
|
||||
print('[success] Found!')
|
||||
b_search = False
|
||||
break
|
||||
|
||||
# --------------------------------------------------
|
||||
|
||||
fformat = op.splitext(fileurl)[1][1:]
|
||||
if (fformat == 'jpg'):
|
||||
fformat = 'jpeg'
|
||||
|
||||
media = mastodon.media_post(requests.get(fileurl).content, f'image/{fformat}')
|
||||
toot = f'This is just a test post nevermind thisjksajskkj.... https://danbooru.donmai.us/posts/{fileid}'
|
||||
|
||||
b_sensetive = bool(set(pulledtags).intersection(TAGS_SENSITIVE))
|
||||
|
||||
if (b_sensetive):
|
||||
print('[success] Marked as sensitive.')
|
||||
|
||||
mastodon.status_post(toot, media_ids=[media], visibility='unlisted', sensitive=b_sensetive)
|
||||
print('[success] Posted!\n----------------------------------\n')
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
@ -1,53 +0,0 @@
|
||||
#!/home/naiji/mastodon/udonge-bot/venv/bin/python
|
||||
import requests
|
||||
import sys
|
||||
import random
|
||||
import os
|
||||
import os.path as op
|
||||
|
||||
from mastodon import Mastodon
|
||||
from datetime import datetime
|
||||
|
||||
# --------------------------------------------------
|
||||
|
||||
DIR_SFW = 'sfw/'
|
||||
DIR_NSFW = 'nsfw/'
|
||||
|
||||
def main():
|
||||
|
||||
mastodon = Mastodon(
|
||||
access_token = 'token.dat',
|
||||
api_base_url = 'https://udongein.xyz/'
|
||||
)
|
||||
|
||||
sfwcount = len([name for name in os.listdir(DIR_SFW) if os.path.isfile(os.path.join(DIR_SFW, name))])
|
||||
nsfwcount = len([name for name in os.listdir(DIR_NSFW) if os.path.isfile(os.path.join(DIR_NSFW, name))])
|
||||
|
||||
random_choice = random.randint(1, sfwcount + nsfwcount)
|
||||
print('\ns:' + str(sfwcount) + ' n:' + str(nsfwcount) + ' r:' + str(random_choice))
|
||||
|
||||
is_safe = False if random_choice < nsfwcount else True
|
||||
art = ""
|
||||
|
||||
if is_safe:
|
||||
files = [f for f in os.listdir(DIR_SFW) if op.isfile(op.join(DIR_SFW, f))]
|
||||
art = DIR_SFW + random.choice(files)
|
||||
else:
|
||||
files = [f for f in os.listdir(DIR_NSFW) if op.isfile(op.join(DIR_NSFW, f))]
|
||||
art = DIR_NSFW + random.choice(files)
|
||||
|
||||
fformat = op.splitext(art)[1][1:]
|
||||
if (fformat == 'jpg'):
|
||||
fformat = 'jpeg'
|
||||
|
||||
with open(art, 'rb') as picture:
|
||||
data = picture.read()
|
||||
|
||||
media = mastodon.media_post(data, f'image/{fformat}')
|
||||
toot = f':gyate_reisen_love:'
|
||||
|
||||
mastodon.status_post(toot, media_ids=[media], visibility='unlisted', sensitive=not is_safe)
|
||||
print(str(datetime.now()) + ': ' + art)
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
@ -1 +0,0 @@
|
||||
mastodon.py
|
@ -1,2 +0,0 @@
|
||||
#!/home/naiji/mastodon/udonge-bot/venv/bin/python
|
||||
python3 post-local.py
|
Loading…
Reference in New Issue