From 4847a5e870ec687b2b52225b6a60a3ff39775017 Mon Sep 17 00:00:00 2001 From: horhik Date: Sun, 14 Nov 2021 23:24:59 +0300 Subject: [PATCH] add time in logging and remove some shit --- src/arguments.py | 9 ++------- src/converters.py | 4 +++- src/main.py | 3 +++ src/network.py | 11 +++++++++++ 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/arguments.py b/src/arguments.py index 958d2ad..15a5dbd 100644 --- a/src/arguments.py +++ b/src/arguments.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import datetime from colorama import Fore, Back, Style def process_arguments(args, defaults): count = 1 @@ -28,14 +29,8 @@ def process_arguments(args, defaults): else: print(Fore.RED + '❗ -> Wrong Argument Name!...') print(Style.RESET_ALL) + print(datetime.datetime.now()) count +=2 return defaults -#fuck this shit im out'' -#teenagers scare the living shit out of me -#deeeespaaaacito quero esperanto de despacito -#хорошо всё будет хорошо -#и камнем вниииз -#u kinda smell *smif* like a BAKA -#Yeren Yegaaaaaaa!!!!!!!!! diff --git a/src/converters.py b/src/converters.py index bd9a6c1..dd4d277 100644 --- a/src/converters.py +++ b/src/converters.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from colorama import Fore, Back, Style +import datetime def split_array(arr, size): count = len(arr) // size + 1 @@ -15,9 +16,10 @@ def try_to_get_carousel(array, post): return urls print(Fore.GREEN + "🎠 > Found carousel!") print(Style.RESET_ALL) + print(datetime.datetime.now()) except Exception as e: print(Fore.RED + "🎠💥 > No carousel :( \n", e) print(Style.RESET_ALL) + print(datetime.datetime.now()) return array - diff --git a/src/main.py b/src/main.py index 1268b6c..88da685 100644 --- a/src/main.py +++ b/src/main.py @@ -2,6 +2,7 @@ import os import sys import time +import datetime import json from mastodon import Mastodon from colorama import Fore, Back, Style @@ -53,12 +54,14 @@ mastodon_carousel_size = settings["carousel-limit"] print(Fore.GREEN + '🚀 > Connecting to Instagram...') print(Style.RESET_ALL) +print(datetime.datetime.now()) L = Instaloader() profile = Profile.from_username(L.context, fetched_user) print(Fore.GREEN + '🚀 > Connecting to Mastodon/Pixelfed...') print(Style.RESET_ALL) +print(datetime.datetime.now()) mastodon = Mastodon( access_token = mastodon_token, api_base_url = mastodon_instance diff --git a/src/network.py b/src/network.py index de34511..d30306c 100644 --- a/src/network.py +++ b/src/network.py @@ -2,6 +2,7 @@ from colorama import Fore, Back, Style import requests import time +import datetime from already_posted import already_posted, mark_as_posted from converters import split_array, try_to_get_carousel import hashlib @@ -10,36 +11,43 @@ def get_image(url): try: print(Fore.YELLOW + "🚀 > Downloading Image...", url) print(Style.RESET_ALL) + print(datetime.datetime.now()) response = requests.get(url) response.raw.decode_content = True print(Fore.GREEN + "✨ > Downloaded!") print(Style.RESET_ALL) + print(datetime.datetime.now()) return response.content except Exception as e: print(Fore.RED + "💥 > Failed to download image. \n", e) print(Style.RESET_ALL) + print(datetime.datetime.now()) def upload_image_to_mastodon(url, mastodon): try: print(Fore.YELLOW + "🐘 > Uploading Image...") print(Style.RESET_ALL) + print(datetime.datetime.now()) media = mastodon.media_post(media_file = get_image(url), mime_type = "image/jpeg") # sending image to mastodon print(Fore.GREEN + "✨ > Uploaded!") print(Style.RESET_ALL) + print(datetime.datetime.now()) return media["id"] except Exception as e: print(Fore.RED + "💥 > failed to upload image to mastodon. \n", e) print(Style.RESET_ALL) + print(datetime.datetime.now()) def toot(urls, title, mastodon, fetched_user ): try: print(Fore.YELLOW + "🐘 > Creating Toot...", title) print(Style.RESET_ALL) + print(datetime.datetime.now()) ids = [] for url in urls: ids.append(upload_image_to_mastodon(url, mastodon)) @@ -52,6 +60,7 @@ def toot(urls, title, mastodon, fetched_user ): except Exception as e: print(Fore.RED + "😿 > Failed to create toot \n", e) print(Style.RESET_ALL) + print(datetime.datetime.now()) def get_new_posts(mastodon, profile, mastodon_carousel_size, post_limit, already_posted_path, using_mastodon, carousel_size, post_interval, fetched_user): posts = profile.get_posts() @@ -63,8 +72,10 @@ def get_new_posts(mastodon, profile, mastodon_carousel_size, post_limit, already if already_posted(str(post.mediaid), already_posted_path): print(Fore.YELLOW + "🐘 > Already Posted ", post.url) print(Style.RESET_ALL) + print(datetime.datetime.now()) continue print("Posting... ", post.url) + print(datetime.datetime.now()) if using_mastodon: urls_arr = split_array(url_arr, carousel_size) for urls in urls_arr: