import requests
import sys
import time
# Containers/Functions
url = 'https://danbooru.donmai.us/posts.json'
api_key = 'xxx'
login = 'xxx'
limit = 200
tags = "looping_animation bouncing_breasts gif_artifacts gif animated_gif animated video"
url_params = {
"limit": limit,
"tags": tags
}
headers = {
'User-Agent': "test/1.0"
}
data = requests.get(url, auth=(login, api_key), params=url_params, headers=headers).json()
url_container = []
error_container = 0
nsfw_rating_dictionary = {
"g": "General",
"s": "Sensitive",
"q": "Questionable",
"e": "Explicit"
}
unaccepted_rating_container = 0
spam_docs_folder = '/home/container/'
banned_tags = ['loli', 'shota', 'gay', 'yaoi', 'kid', 'child']
def Check_tags(tags):
global banned_tags
for i in banned_tags:
if i in tags:
return True
return False
# Main Menu
choice = "default"
# Webhook selection
# Rating selection
print()
print('Danbooru has 4 "nsfw" ratings.\n')
print('g = general (Fully SFW)')
print('s = sensitive (Somewhat NSFW)')
print('q = questionable (Almost Explicit NSFW)')
print('e = explicit (Full NSFW)\n')
nsfw_rating = "all"
# Checks if all selected or not.
if nsfw_rating == 'all':
nsfw_rating_container = ['e']
else:
nsfw_rating_container = [*nsfw_rating]
print()
for i in nsfw_rating_container:
print(f"{nsfw_rating_dictionary[i]} rating has been selected")
page_number = 1
max_pages = 10000 # Maximum number of pages before exiting the loop
# Actual code for the bot (technically a script, but can be turned into a bot.)
condition = True
while condition and page_number <= max_pages:
new_url = url + '&page=' + str(page_number) # Removed the tag from the URL
time.sleep(5)
headers = {
'User-Agent': "AE-mommy/1.0"
}
r = requests.get(new_url, headers=headers)
data = r.json()
for i in data:
try:
if 'id' not in i:
error_container += 1
elif 'file_url' not in i:
error_container += 1
elif '.zip' in i['file_url']:
error_container += 1
elif i['rating'] not in nsfw_rating_container:
unaccepted_rating_container += 1
elif Check_tags(i['tag_string'].split()):
error_container += 1
else:
url_container.append(i['file_url'])
print(f"Fetched image URL: {i['file_url']}") # Add this line to display the URL
time.sleep(5)
except:
error_container += 1
# Statistics Info.
print('Current Page number is: ' + str(page_number))
print('Current amount of links posted/recorded is: ' + str(len(url_container)))
print('Current Rating-Blocked links: ' + str(unaccepted_rating_container))
print()
page_number += 1
if page_number > 500:
page_number = 1 # Reset page_number to 1
if len(data) == 0:
condition = False
# Post-Process Information
print()
print('There are ' + str(error_container) + ' Deleted/Banned Or Invalid Files.')
print(f'Leaving {str(len(url_container))} out of {str(unaccepted_rating_container+len(url_container)+error_container)} links to be processed.')
if len(url_container) == 0:
print('No Results have been found, double-check the tags given.')
input('')
sys.exit()
file_name = input('Enter the name of Docs:\n>>>')
print()
print(f"'{file_name}' has been chosen as file name")
with open(f'{spam_docs_folder}{file_name}.txt', 'w') as f:
for i in range(0, len(url_container), 5):
f.write('\n'.join(url_container[i:i+5]) + '\n' + '\n')
print()
input(f"Links have been copied into the .txt file: '{file_name}'")