-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
53 lines (41 loc) · 1.46 KB
/
main.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
import os
import sys
import threading
import time
import config
from glob import glob
sys.path.append(os.path.join(sys.path[0], "../../"))
import schedule
from instabot import Bot, utils
bot = Bot()
bot.login(username=config.USERNAME, password=config.PASSWORD)
bot.logger.info("ULTIMATE script. Safe to run 24/7!")
posted_pic_list = utils.file(config.POSTED_PICS_FILE).list
pics = sorted([os.path.basename(x) for x in glob(config.PICS_PATH + "/*.jpg")])
def upload_pictures():
try:
for pic in pics:
if pic in posted_pic_list:
continue
bot.logger.info("Uploading " + pic)
bot.upload_photo(config.PICS_PATH + pic, caption="")
if bot.api.last_response.status_code != 200:
bot.logger.error("Something went wrong, read the following ->\n")
bot.logger.error(bot.api.last_response)
break
if pic not in posted_pic_list:
posted_pic_list.append(pic)
with open("pics.txt", "a") as f:
f.write(pic + "\n")
bot.logger.info("Succesfully uploaded: " + pic)
break
except Exception as e:
bot.logger.error("Couldn't upload pic")
bot.logger.error(str(e))
def run_threaded(job_fn):
job_thread = threading.Thread(target=job_fn)
job_thread.start()
schedule.every(4).hours.do(run_threaded, upload_pictures)
while True:
schedule.run_pending()
time.sleep(1)