-
Notifications
You must be signed in to change notification settings - Fork 0
/
instapub.py
56 lines (47 loc) · 1.59 KB
/
instapub.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
import time
import logging
import image_utils
from instabot import Bot
from dotenv import load_dotenv
load_dotenv()
INSTA_LOGIN = os.getenv("INSTA_LOGIN")
INSTA_PASSWORD = os.getenv("INSTA_PASSWORD")
def upload_photo(image):
bot = Bot()
bot.login(username=INSTA_LOGIN, password=INSTA_PASSWORD)
bot.upload_photo(image)
def remove_garbage():
images = image_utils.get_list_of_images()
garbage_files =['blacklist', 'comments', 'followed', 'friends', 'skipped', 'unfollowed', 'whitelist']
for file in garbage_files:
try:
logging.debug(f'Removing \"{file}.txt\"')
os.remove(f'{file}.txt')
except FileNotFoundError:
logging.exception('Exception in remove_garbage: ')
pass
for image in images:
if image.find('CONVERTED') > 0:
print(f'Removing \"{image}\"')
os.remove(image)
logging.debug('All garbage removed')
if __name__ == '__main__':
remove_garbage()
pause = 60
try:
with open('posted_pics.txt', 'r', encoding='utf8') as f:
posted_pic_list = f.read().splitlines()
except FileNotFoundError:
logging.exception('Exception occurred')
posted_pic_list = []
images = image_utils.get_list_of_images()
logging.debug(posted_pic_list)
for image in images:
if image not in posted_pic_list:
upload_photo(image)
posted_pic_list.append(image)
with open('posted_pics.txt', 'a', encoding='utf8') as f:
f.write(image + "\n")
time.sleep(pause)
remove_garbage()