Compare commits

..

3 Commits

3 changed files with 14 additions and 22 deletions

View File

@ -19,7 +19,7 @@
from collections import OrderedDict
def setup_profile(name, backend, tags, banned_tags, message, message_nsfw, force_nsfw=None):
def setup_profile(name, backend, banned_tags, tags, message, message_nsfw, force_nsfw=None):
post_setting = {
"name": name,
"backend": backend,
@ -93,6 +93,6 @@ banned_tags = (
# Apply post settings
settings_post = (
setup_profile("danbooru.random", "danbooru_backend", ("random",), banned_tags, "#random", "#random #lewd #nsfw", None),
setup_profile("danbooru.yandere", "danbooru_backend", ("yandere",), banned_tags, "#yandere", "#yandere #lewd #nsfw", None),
setup_profile("danbooru.random", "danbooru_backend", banned_tags, ("random",), "#random", "#random #nsfw #lewd"),
setup_profile("danbooru.yandere", "danbooru_backend", banned_tags, ("yandere",), "#yandere", "#yandere #nsfw #lewd"),
)

View File

@ -2,9 +2,7 @@
# TODO:
# Update to enable multiple file downloads
# Update to include safe/nsfw filter
import magic
import requests
import os
@ -52,7 +50,8 @@ class downloader:
username = None
password = None
tmp = None
limit=50
# Limit for posts.json is 200
limit=100
def __init__(self, username=None, password=None, tmp="/tmp"):
self.username = username
@ -113,13 +112,7 @@ class downloader:
r = {
# Add profile to dictioanry
"name": profile["name"],
"backend": profile["backend"],
"tags": profile["tags"],
"message": profile["message"],
"message_nsfw": profile["message_nsfw"],
"force_nsfw": profile["force_nsfw"],
"banned_tags": profile["banned_tags"],
"profile": profile,
# Query results
"search_url": search_url,

View File

@ -19,7 +19,6 @@
import os
import datetime
import contextlib
import fnmatch
import math
import shutil
import importlib
@ -122,14 +121,14 @@ class YandereBot:
# Maybe I should remove this from the backend?
def print_header_stats(self, picked, date_selection, date_next_selection):
picked_name = picked["name"] if picked else None
picked_name = picked["profile"]["name"] if picked else None
picked_url = picked["file_url"] if picked else None
picked_path = picked["full_path"] if picked else None
picked_nsfw = picked["nsfw"] if picked else None
picked_index = (self.currentIndexCount % len(self.settings_post)) - 1
next_selection_seconds = max(0, int(time_diff_seconds(date_next_selection, date_selection)))
print("[Profile]", picked_name)
print(picked_path)
print("[Profile]", picked_name, "[Index]", picked_index)
print(picked_url)
print("Explicit:", picked_nsfw)
print("Selection time: {}".format(
@ -142,23 +141,23 @@ class YandereBot:
# Returns a list of media paths (without the hashes)
def download_media(self, picked):
def download_media(self, picked_profile):
try:
backend_s = picked["backend"]
backend_s = picked_profile["backend"]
backend = importlib.import_module(backend_s)
username = self.settings_credentials[backend_s]["username"]
password = self.settings_credentials[backend_s]["password"]
img = None
downloader = backend.downloader(username, password, tmp=self.settings_behavior["tmp_dir"])
img = downloader.fetch_post(picked)
img = downloader.fetch_post(picked_profile)
if img is None:
raise InvalidPost("Img could not be downloaded")
return downloader.download_post(img)
except ImportError:
print("Invalid Backend:", picked["backend"])
print("Invalid Backend:", picked_profile["backend"])
return None
# Returns a list of tuples that contain the media list path and media mastodon dictionary
@ -172,7 +171,7 @@ class YandereBot:
content_type = self.settings_behavior["content_type"]
content_newline = self.settings_behavior["content_newline"]
nsfw = picked["nsfw"]
message = picked["message_nsfw"] if nsfw else picked["message"]
message = picked["profile"]["message_nsfw"] if nsfw else picked["profile"]["message"]
static_message = content_newline.join(message)
string_post = ""
string_imglinks = []