master
NaiJi ✨ 3 years ago
parent 1a402b9a64
commit def72534fb

@ -1,3 +1,5 @@
#!/home/naiji/mastodon/vndb-bot/venv/bin/python
import re
import sys
import random
@ -8,12 +10,13 @@ from bs4 import BeautifulSoup
from mastodon import Mastodon
URL_HEAD = 'https://vndb.org/v/rand'
FORBIDDEN_TAGS = [2023, 1640, 2600, 84, 156, 162, 897, 214, 391, 98, 2047, 1341, 83]
FORBIDDEN_TAGS = [2023, 156, 162, 897, 391, 98, 2047, 1341, 83]
def main():
#Logging into VNDB
vndb = v.VNDB('VNDBbot', '0.1', 'LOGIN', 'PASSWORD')
id = -1
safe = True
while True: # Searching for a good vn
@ -43,7 +46,7 @@ def main():
popularity = vn_stats['popularity'] if vn_stats['popularity'] else -1
rating = vn_stats['rating'] if vn_stats['rating'] else -1
votecount = vn_stats['votecount'] if vn_stats['votecount'] else -1
if votecount < 10 or rating < 5 or popularity < 2:
if votecount < 10 or rating < 5 or popularity < 0.8:
continue
# getting details of the VN
@ -51,25 +54,23 @@ def main():
vn_details = vndb_result['items'][0]
# even slightly suggestive or slightly violent go to Sensitive, so we skip it
if (vn_details['image_flagging']['sexual_avg'] != 0) or (vn_details['image_flagging']['violence_avg'] != 0):
continue
if (vn_details['image_flagging']['sexual_avg'] > 1) or (vn_details['image_flagging']['violence_avg'] > 1):
safe = False
# getting basic information of the VN
vndb_result = vndb.get('vn', 'basic', '(id=' + str(id) + ')', '')
vn_basic = vndb_result['items'][0]
title = vn_basic['title'] if vn_basic['title'] else ''
raw_description = vn_details['description'] if vn_details['description'] else ''
description = vn_details['description'] if vn_details['description'] else ''
released = vn_basic['released'] if vn_basic['released'] else 'unknown'
link = 'https://vndb.org/v' + str(id)
# processing description and removing markdown
description = re.sub('^\[.rom.*\[\/url\]\].*', '', raw_description)
# logging in and posting
mastodon = Mastodon(
access_token = 'token.dat',
api_base_url = 'https://udongein.xyz/'
api_base_url = 'https://udongein.xyz/',
feature_set = 'pleroma'
)
text = title + '\n- - - - - - - -\n\n' + description + '\n\nReleased: ' + released + '\nPopularity: ' + (str(popularity) if popularity > -1 else 'unknown') + '\nRating:' + str(rating) + '\n\n' + link
@ -78,13 +79,17 @@ def main():
vndb_result = vndb.get('vn', 'screens', '(id=' + str(id) + ')', '')
vn_screens = vndb_result['items'][0]['screens']
screens = [ ]
counter = 0
screens.append(mastodon.media_post(requests.get(vn_details['image']).content, 'image/jpeg'))
for screen in vn_screens:
if screen['flagging']['sexual_avg'] == 0 and screen['flagging']['violence_avg'] == 0:
screens.append(mastodon.media_post(requests.get(screen['image']).content, 'image/jpeg'))
counter += 1
if counter == 3:
break
mastodon.status_post(text, media_ids=screens, visibility='unlisted', sensitive=False)
mastodon.status_post(text, media_ids=screens, visibility='unlisted', sensitive=not safe, content_type='text/bbcode')
break
if __name__ == '__main__':
sys.exit(main())
sys.exit(main())

Loading…
Cancel
Save