2929global thread_instaPy
3030thread_instaPy = None
3131
32- # Enable logging
33- #logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
34- #logger = logging.getLogger(__name__)
35-
3632# Declare thread
3733class customThread (threading .Thread ):
3834 def __init__ (self , name ):
3935 threading .Thread .__init__ (self )
4036 self .name = name
41- def setTelegram (self , bot , job ):
37+ def setTelegram (self , bot , chatid ):
4238 self .bot = bot
43- self .job = job
39+ self .chatid = chatid
4440 def run (self ):
4541 start = datetime .datetime .now ().replace (microsecond = 0 )
46- self .bot .send_message (self .job . context , text = 'InstaPy Bot start at {}' .format (time .strftime ("%X" )))
42+ self .bot .send_message (self .chatid , text = 'InstaPy Bot start at {}' .format (time .strftime ("%X" )))
4743
4844 threadRun ()
4945
5046 endTime = time .strftime ("%X" )
5147 end = datetime .datetime .now ().replace (microsecond = 0 )
52- self .bot .send_message (self .job . context , text = 'InstaPy Bot end at {}\n Execution time {}' .format (time .strftime ("%X" ), end - start ))
48+ self .bot .send_message (self .chatid , text = 'InstaPy Bot end at {}\n Execution time {}' .format (time .strftime ("%X" ), end - start ))
5349
5450 # Read the last 9 line to get ended status of InstaPy.
5551 with open ('logs/general.log' , "r" ) as f :
@@ -59,8 +55,8 @@ def run(self):
5955 lines = f .readlines () # Read to end
6056
6157 lines = lines [- 9 :] # Get last 10 lines
62- message = '' .join (str (x ) for x in lines )
63- self .bot .send_message (self .job . context , text = message )
58+ message = '' .join (str (x . replace ( "INFO - " , "" ) ) for x in lines )
59+ self .bot .send_message (self .chatid , text = message )
6460
6561
6662def help (bot , update ):
@@ -80,7 +76,7 @@ def threadRun():
8076 insta_password = config .get ('instapy' , 'password' );
8177
8278 # Login
83- session = InstaPy (username = insta_username , password = insta_password , nogui = True , page_delay = random .randint (24 ,31 ))
79+ session = InstaPy (username = insta_username , password = insta_password , headless_browser = True , page_delay = random .randint (24 ,31 ), show_logs = True )
8480 session .login ()
8581
8682 # Comments
@@ -92,40 +88,50 @@ def threadRun():
9288 comments .append (line .strip ("\n " ))
9389 random .shuffle (comments )
9490 session .set_comments (comments )
91+
9592 # Follow
9693 session .set_do_follow (enabled = True , percentage = random .randint (10 ,25 ), times = 3 )
97- session .set_user_interact (amount = 10 , randomize = True , percentage = random .randint (20 ,80 ), media = 'Photo' )
94+ session .set_user_interact (amount = random . randint ( 7 , 13 ) , randomize = True , percentage = random .randint (20 ,80 ), media = 'Photo' )
9895
9996 # Unfollow
10097 session .unfollow_users (amount = random .randint (10 ,40 ), onlyInstapyFollowed = True , onlyInstapyMethod = 'FIFO' , sleep_delay = random .randint (50 ,60 ))
98+
10199 # Limits
102100 session .set_lower_follower_count (limit = 800 )
103- session .set_upper_follower_count (limit = 2500 )
101+ session .set_upper_follower_count (limit = 5000 )
104102
105103 # Like
106- hashtags = ["telegram" ]
104+ hashtags = []
107105 # Read hashtags from file and shuffle
108- with open ('telegram-bot-data/resources/hashtags_' + str (random .randint (1 ,3 )) + '.txt' ) as f :
106+ with open ('telegram-bot-data/resources/hashtags_' + str (random .randint (1 ,6 )) + '.txt' ) as f :
109107 for line in f :
110- hashtags .append (line .strip ("\n " ))
108+ hashtags .append (line .strip ("\n " ). replace ( '#' , '' ) )
111109 random .shuffle (hashtags )
112- session .like_by_tags (hashtags , amount = random .randint (8 ,15 ))
110+ session .set_smart_hashtags (hashtags , limit = random .randint (3 ,8 ), sort = 'top' , log_tags = False )
111+ session .like_by_tags (amount = random .randint (6 ,15 ), use_smart_hashtags = True )
112+ #session.like_by_tags(['love'], amount=3)
113113
114114 session .end ()
115115 except :
116116 import traceback
117117 print (traceback .format_exc ())
118118
119- def execThread (bot , job ):
119+ def _execThread (bot , id ):
120120 # If thread is not alive or not create start it.
121121 global thread_instaPy
122122 if not thread_instaPy or not thread_instaPy .isAlive ():
123123 thread_instaPy = customThread ("Thread-InstaPy" )
124- thread_instaPy .setTelegram (bot , job )
124+ thread_instaPy .setTelegram (bot , id )
125125 thread_instaPy .start ()
126126 else :
127127 bot .send_message (job .context , text = 'Bot already executing!' )
128128
129+ def execThread (bot , job ):
130+ _execThread (bot , job .context )
131+
132+ def now (bot , update ):
133+ _execThread (bot , update .message .chat_id )
134+
129135def statusThread (bot , update ):
130136 # Responde with the status of thread.
131137 if not thread_instaPy or not thread_instaPy .isAlive ():
@@ -229,10 +235,6 @@ def printJobs(bot, update, chat_data):
229235 else :
230236 update .message .reply_text ("Job not setted" )
231237
232- def error (bot , update , error ):
233- logger .warning ('Update "%s" caused error "%s"' % (update , error ))
234-
235-
236238def main ():
237239 updater = Updater (telegram_token )
238240
@@ -246,15 +248,13 @@ def main():
246248 dp .add_handler (CommandHandler ("status" , statusThread ))
247249
248250 dp .add_handler (CommandHandler ("set" , set , pass_args = True , pass_job_queue = True , pass_chat_data = True ))
251+ dp .add_handler (CommandHandler ("now" , now ))
249252
250253 dp .add_handler (CommandHandler ("unset" , unset , pass_args = True , pass_chat_data = True ))
251254 dp .add_handler (CommandHandler ("print" , printJobs , pass_chat_data = True ))
252255
253256 dp .add_handler (CallbackQueryHandler (dayChoose , pass_job_queue = True , pass_chat_data = True ))
254257
255- # log all errors
256- dp .add_error_handler (error )
257-
258258 updater .start_polling ()
259259
260260 # Block until you press Ctrl-C or the process receives SIGINT, SIGTERM or
0 commit comments