-
Notifications
You must be signed in to change notification settings - Fork 1
/
__init__.py
69 lines (56 loc) · 2.54 KB
/
__init__.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
57
58
59
60
61
62
63
64
65
66
67
68
69
import schedule
import time
import os
import sys
import threading
sys.path.append(os.path.join(sys.path[0], './src'))
from bot_insta import BotInsta
# https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html
def check_server():
""" Checks server status """
datetime = time.strftime("%d/%b/%Y %H:%M:%S")
print("[{}] I'M STILL ALIVE".format(datetime))
def job_after_server_init(params):
"""Execute a function only one time
Parameters:
params (tuple): [0] contains function to execute
and [1:] params of the functions
"""
print("====================================")
print("===== Executed only one time =======")
print("====================================")
ejecutar = params[0]
(master_username, text_message) = params[1:]
ejecutar(master_username, text_message)
return schedule.CancelJob
def run_threaded(params):
"""Execute a function only one time
Parameters:
params (tuple): [0] contains function to execute
and [1:] params of the functions
"""
print("====================================")
print("I'm running on thread %s" % threading.current_thread())
job_thread = threading.Thread(target=params[0], args=params[1:])
job_thread.start()
# https://medium.com/dataseries/hiding-secret-info-in-python-using-environment-variables-a2bab182eea
username = os.environ.get('username')
password = os.environ.get('password')
# username that will receive notifications about posts
master_username = os.environ.get('master_username')
# message text of the notifications
text_message_photo = "{}\n\nwasup! Master, quiondas, mirá, acabo de hacer ésta publicación.\n\n========="
text_message_story = "{}\n\nwasup! Master, quiondas, mirá, acabo de publicar una historia.\n\n=========="
bot = BotInsta()
bot.login(username, password)
# https://schedule.readthedocs.io/en/stable/
schedule.every().minute.do(check_server)
""" Check bot_insta.py. Line 49 and 52 """
# schedule.every(30).minutes.do(bot.check_followers)
schedule.every(5).to(10).minutes.do(job_after_server_init,( bot.make_publication_photo, master_username, text_message_photo ))
schedule.every(20).to(30).minutes.do(job_after_server_init,( bot.make_publication_story, master_username, text_message_story ))
schedule.every(6).to(7).hours.do(run_threaded,( bot.make_publication_photo, master_username, text_message_photo ))
schedule.every(4).to(5).hours.do(run_threaded,( bot.make_publication_story, master_username, text_message_story ))
while True:
schedule.run_pending()
time.sleep(1)