Compare commits
No commits in common. "068937803e471a71caf0963466d3b8c22f775453" and "efa84c6bae6689f0cdc2a7623e9860a5ab9e53d1" have entirely different histories.
068937803e
...
efa84c6bae
@ -19,7 +19,7 @@
|
|||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
|
||||||
def setup_profile(name, backend, banned_tags, tags, message, message_nsfw, force_nsfw=None):
|
def setup_profile(name, backend, tags, banned_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", banned_tags, ("random",), "#random", "#random #nsfw #lewd"),
|
setup_profile("danbooru.random", "danbooru_backend", ("random",), banned_tags, "#random", "#random #lewd #nsfw", None),
|
||||||
setup_profile("danbooru.yandere", "danbooru_backend", banned_tags, ("yandere",), "#yandere", "#yandere #nsfw #lewd"),
|
setup_profile("danbooru.yandere", "danbooru_backend", ("yandere",), banned_tags, "#yandere", "#yandere #lewd #nsfw", None),
|
||||||
)
|
)
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
# 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
|
||||||
|
|
||||||
@ -50,8 +52,7 @@ class downloader:
|
|||||||
username = None
|
username = None
|
||||||
password = None
|
password = None
|
||||||
tmp = None
|
tmp = None
|
||||||
# Limit for posts.json is 200
|
limit=50
|
||||||
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
|
||||||
@ -112,7 +113,13 @@ class downloader:
|
|||||||
|
|
||||||
r = {
|
r = {
|
||||||
# Add profile to dictioanry
|
# Add profile to dictioanry
|
||||||
"profile": profile,
|
"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"],
|
||||||
|
|
||||||
# Query results
|
# Query results
|
||||||
"search_url": search_url,
|
"search_url": search_url,
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
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
|
||||||
@ -121,14 +122,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["profile"]["name"] if picked else None
|
picked_name = picked["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, "[Index]", picked_index)
|
print("[Profile]", picked_name)
|
||||||
|
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(
|
||||||
@ -141,23 +142,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_profile):
|
def download_media(self, picked):
|
||||||
try:
|
try:
|
||||||
backend_s = picked_profile["backend"]
|
backend_s = picked["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_profile)
|
img = downloader.fetch_post(picked)
|
||||||
|
|
||||||
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_profile["backend"])
|
print("Invalid Backend:", picked["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
|
||||||
@ -171,7 +172,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["profile"]["message_nsfw"] if nsfw else picked["profile"]["message"]
|
message = picked["message_nsfw"] if nsfw else picked["message"]
|
||||||
static_message = content_newline.join(message)
|
static_message = content_newline.join(message)
|
||||||
string_post = ""
|
string_post = ""
|
||||||
string_imglinks = []
|
string_imglinks = []
|
||||||
|
Reference in New Issue
Block a user