add sha1 to already_posted function
This commit is contained in:
parent
9186df4f3a
commit
6da50cdda6
19
src/main.py
19
src/main.py
|
@ -2,6 +2,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import requests
|
import requests
|
||||||
import time
|
import time
|
||||||
|
import hashlib
|
||||||
from mastodon import Mastodon
|
from mastodon import Mastodon
|
||||||
from colorama import Fore, Back, Style
|
from colorama import Fore, Back, Style
|
||||||
from instaloader import Profile, Instaloader
|
from instaloader import Profile, Instaloader
|
||||||
|
@ -15,7 +16,7 @@ fetched_user = sys.argv[1]
|
||||||
mastodon_instance = sys.argv[2]
|
mastodon_instance = sys.argv[2]
|
||||||
mastodon_token = sys.argv[3]
|
mastodon_token = sys.argv[3]
|
||||||
|
|
||||||
post_limit = 7
|
post_limit = 100
|
||||||
time_interval_sec = 1000
|
time_interval_sec = 1000
|
||||||
|
|
||||||
print(Fore.GREEN + '🚀 > Connecting to Instagram...')
|
print(Fore.GREEN + '🚀 > Connecting to Instagram...')
|
||||||
|
@ -52,17 +53,18 @@ def get_image(url):
|
||||||
|
|
||||||
def already_posted(id):
|
def already_posted(id):
|
||||||
file = open(id_filename);
|
file = open(id_filename);
|
||||||
content = file.read()
|
content = file.read().split("\n")
|
||||||
if id in content:
|
sha1 = hashlib.sha1(bytes(id, "utf-8")).hexdigest()
|
||||||
|
if sha1 in content:
|
||||||
file.close()
|
file.close()
|
||||||
return True
|
return True
|
||||||
else:
|
|
||||||
file.close()
|
file.close()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def mark_as_posted(id):
|
def mark_as_posted(id):
|
||||||
file = open(id_filename, 'a');
|
file = open(id_filename, 'a');
|
||||||
file.write(id + "\n")
|
sha1 = hashlib.sha1(bytes(id, "utf-8")).hexdigest()
|
||||||
|
file.write(sha1+'\n')
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
def upload_image_to_mastodon(url):
|
def upload_image_to_mastodon(url):
|
||||||
|
@ -122,12 +124,13 @@ def get_new_posts():
|
||||||
stupidcounter = 0
|
stupidcounter = 0
|
||||||
for post in posts:
|
for post in posts:
|
||||||
stupidcounter += 1
|
stupidcounter += 1
|
||||||
if stupidcounter < post_limit:
|
if stupidcounter <= post_limit:
|
||||||
if already_posted(str(post.url)):
|
if already_posted(str(post.url)):
|
||||||
print(Fore.YELLOW + "🐘 > Already Posted", stupidcounter, " of ", posts.count)
|
print(Fore.YELLOW + "🐘 > Already Posted ", post.url)
|
||||||
print(Style.RESET_ALL)
|
print(Style.RESET_ALL)
|
||||||
continue
|
continue
|
||||||
toot(post.url, post.caption)
|
print("Posting... ", post.url)
|
||||||
|
# toot(post.url, post.caption)
|
||||||
mark_as_posted(str(post.url))
|
mark_as_posted(str(post.url))
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue