Compare commits

..

3 Commits

3 changed files with 14 additions and 22 deletions

View File

@ -19,7 +19,7 @@
from collections import OrderedDict 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 = { post_setting = {
"name": name, "name": name,
"backend": backend, "backend": backend,
@ -93,6 +93,6 @@ banned_tags = (
# Apply post settings # Apply post settings
settings_post = ( settings_post = (
setup_profile("danbooru.random", "danbooru_backend", ("random",), banned_tags, "#random", "#random #lewd #nsfw", None), setup_profile("danbooru.random", "danbooru_backend", banned_tags, ("random",), "#random", "#random #nsfw #lewd"),
setup_profile("danbooru.yandere", "danbooru_backend", ("yandere",), banned_tags, "#yandere", "#yandere #lewd #nsfw", None), setup_profile("danbooru.yandere", "danbooru_backend", banned_tags, ("yandere",), "#yandere", "#yandere #nsfw #lewd"),
) )

View File

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

View File

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