Simplified posting logic
This commit is contained in:
parent
1b6a032324
commit
6bd67334a9
@ -118,14 +118,14 @@ class YandereBot:
|
|||||||
except (MastodonIllegalArgumentError, MastodonVersionError) as e:
|
except (MastodonIllegalArgumentError, MastodonVersionError) as e:
|
||||||
print(e)
|
print(e)
|
||||||
raise FailedLogin
|
raise FailedLogin
|
||||||
|
|
||||||
# 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["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 = max(0, self.currentIndexCount - 1) % len(self.settings_post)
|
picked_index = (self.currentIndexCount - int(self.currentSessionCount > 0)) % len(self.settings_post)
|
||||||
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, "[Index]", picked_index)
|
||||||
@ -247,7 +247,7 @@ class YandereBot:
|
|||||||
if tag_select == "random":
|
if tag_select == "random":
|
||||||
pick_index = random.randint(0, len(profiles) - 1)
|
pick_index = random.randint(0, len(profiles) - 1)
|
||||||
elif tag_select == "sequential":
|
elif tag_select == "sequential":
|
||||||
pick_index = max(0, self.currentIndexCount % len(profiles))
|
pick_index = self.currentIndexCount % len(profiles)
|
||||||
return profiles[pick_index]
|
return profiles[pick_index]
|
||||||
|
|
||||||
|
|
||||||
@ -280,42 +280,27 @@ class YandereBot:
|
|||||||
|
|
||||||
# Invalid post (move to next profile)
|
# Invalid post (move to next profile)
|
||||||
except InvalidPost as e:
|
except InvalidPost as e:
|
||||||
|
self.currentIndexCount += 1
|
||||||
print("Invalid post:", e)
|
print("Invalid post:", e)
|
||||||
|
|
||||||
|
# Invalid post (remove downloaded files)
|
||||||
except (FileTooLarge, InvalidMimeType) as e:
|
except (FileTooLarge, InvalidMimeType) as e:
|
||||||
os.remove(picked["full_path"])
|
os.remove(picked["full_path"])
|
||||||
self.currentIndexCount -= 1
|
|
||||||
print("Unable to post:", e)
|
print("Unable to post:", e)
|
||||||
|
|
||||||
except FileNotFoundError as e:
|
# Server Errors and other general exceptions
|
||||||
self.currentIndexCount -= 1
|
# Assume all exceptions are on the server side (besides FileNotFoundError of course)
|
||||||
print("File not found:", e)
|
|
||||||
|
|
||||||
# Check if the file limit has been reached
|
|
||||||
except MastodonAPIError as e:
|
|
||||||
# Check if the file limit has been reached (413 error)
|
|
||||||
file_limit_reached = False
|
|
||||||
with contextlib.suppress(IndexError):
|
|
||||||
file_limit_reached = (e.args[1] == 413)
|
|
||||||
if file_limit_reached:
|
|
||||||
self.currentIndexCount -= 1
|
|
||||||
|
|
||||||
print("API Error:", e)
|
|
||||||
|
|
||||||
# Server Errors
|
|
||||||
# Assume all exceptions are on the server side
|
|
||||||
# If the connection is timing out it could be for two reasons:
|
# If the connection is timing out it could be for two reasons:
|
||||||
# 1. The error was caused by the user attempting to upload a large file over a slow connection:
|
# 1. The error was caused by the user attempting to upload a large file over a slow connection:
|
||||||
# a. FIX: Reduce settings_behavior["max_size"]
|
# a. FIX: Reduce settings_behavior["max_size"]
|
||||||
# 2. The server is down. Check to verify in a web browser (this is the default assumption since the
|
# 2. The server is down. Check to verify in a web browser (this is the default assumption since the
|
||||||
# mastodon.py API will not specify why the connection timed out).
|
# mastodon.py API will not specify why the connection timed out).
|
||||||
# The default assumption is #2
|
# The default assumption is #2
|
||||||
except Exception as e:
|
except (FileNotFoundError, MastodonAPIError, Exception) as e:
|
||||||
print("Unhandled Exception:", e)
|
print("Exception:", e)
|
||||||
|
|
||||||
# An exception occurred
|
# An exception occurred
|
||||||
self.failed_uploads += 1
|
self.failed_uploads += 1
|
||||||
self.currentIndexCount += 1
|
|
||||||
print("[Errors: {}]".format(self.failed_uploads))
|
print("[Errors: {}]".format(self.failed_uploads))
|
||||||
|
|
||||||
# Sleep
|
# Sleep
|
||||||
@ -380,7 +365,11 @@ class YandereBot:
|
|||||||
# 1. User presses Ctrl+C
|
# 1. User presses Ctrl+C
|
||||||
# 2. settings_behavior["uploads_per_post"] is less than one for some reason
|
# 2. settings_behavior["uploads_per_post"] is less than one for some reason
|
||||||
def can_post(self):
|
def can_post(self):
|
||||||
return not self.eventSleep.is_set() and self.settings_behavior["uploads_per_post"] > 0
|
return (
|
||||||
|
not self.eventSleep.is_set() and
|
||||||
|
self.settings_behavior["uploads_per_post"] > 0 and
|
||||||
|
self.currentIndexCount >= 0
|
||||||
|
)
|
||||||
|
|
||||||
def main_loop(self):
|
def main_loop(self):
|
||||||
target_posts = self.settings_behavior["uploads_per_post"]
|
target_posts = self.settings_behavior["uploads_per_post"]
|
||||||
|
Reference in New Issue
Block a user