@@ -121,7 +121,7 @@ def likes_rt_home(bot, logger, tweet_count, likes_count, retweet_count):
121121
122122 try :
123123 home = get_home (bot )
124- except twitter . api . TwitterHTTPError as e :
124+ except Exception as e :
125125 errors .error_handler (e )
126126
127127 if home is not None :
@@ -132,12 +132,12 @@ def likes_rt_home(bot, logger, tweet_count, likes_count, retweet_count):
132132
133133 try :
134134 likes_count = put_like (bot , tweet_home , logger , likes_count )
135- except twitter . api . TwitterHTTPError as e :
135+ except Exception as e :
136136 errors .error_handler (e )
137137
138138 try :
139139 retweet_count = retweet_tweet (bot , tweet_home , logger , retweet_count )
140- except twitter . api . TwitterHTTPError as e :
140+ except Exception as e :
141141 errors .error_handler (e )
142142
143143 time .sleep (2 )
@@ -152,7 +152,7 @@ def likes_rt_user(bot, logger, tweet_count, likes_count, retweet_count):
152152 """
153153 try :
154154 home = get_friend_home (bot , globals .user )
155- except twitter . api . TwitterHTTPError as e :
155+ except Exception as e :
156156 errors .error_handler (e )
157157
158158 if home is not None :
@@ -163,20 +163,20 @@ def likes_rt_user(bot, logger, tweet_count, likes_count, retweet_count):
163163
164164 try :
165165 likes_count = put_like (bot , tweet_home , logger , likes_count )
166- except twitter . api . TwitterHTTPError as e :
166+ except Exception as e :
167167 errors .error_handler (e )
168168
169169 try :
170170 retweet_count = retweet_tweet (bot , tweet_home , logger , retweet_count )
171- except twitter . api . TwitterHTTPError as e :
171+ except Exception as e :
172172 errors .error_handler (e )
173173
174174 time .sleep (2 )
175175
176176 return tweet_count , likes_count , retweet_count
177177
178178
179- def crawl_timeline (bot , logger ):
179+ def crawl_timeline (bot , logger , no_user ):
180180 """
181181 This is the handle function of the -t or --timeline option.
182182 """
@@ -219,9 +219,14 @@ def crawl_timeline(bot, logger):
219219 logger .info ("Sleeping for one minute." )
220220 time .sleep (60 )
221221
222- tweet_count , likes_count , retweet_count = likes_rt_user (
223- bot , logger , tweet_count , likes_count , retweet_count
224- )
222+ if no_user :
223+ tweet_count , likes_count , retweet_count = likes_rt_home (
224+ bot , logger , tweet_count , likes_count , retweet_count
225+ )
226+ else :
227+ tweet_count , likes_count , retweet_count = likes_rt_user (
228+ bot , logger , tweet_count , likes_count , retweet_count
229+ )
225230
226231 # update the values in the database
227232 today = datetime .datetime .today ().strftime ("%Y-%m-%d" )
@@ -230,7 +235,7 @@ def crawl_timeline(bot, logger):
230235 # retrieve the up-to-date followers count
231236 try :
232237 followers_count = followers (bot , globals .bot_user )
233- except twitter . api . TwitterHTTPError as e :
238+ except Exception as e :
234239 errors .error_handler (e )
235240
236241 # if there aren't data, creates a record in the statistics table
@@ -290,7 +295,7 @@ def likes_rt_search(bot, logger, keyword, tweet_count, likes_count, retweet_coun
290295 return tweet_count , likes_count , retweet_count
291296
292297
293- def crawl_keyword (bot , logger , keyword ):
298+ def crawl_keyword (bot , logger , keyword , no_user ):
294299 """
295300 This is the handle function of the -k or --keyword option.
296301 """
@@ -330,12 +335,18 @@ def crawl_keyword(bot, logger, keyword):
330335 tweet_count , likes_count , retweet_count = likes_rt_search (
331336 bot , logger , keyword , tweet_count , likes_count , retweet_count
332337 )
338+
333339 logger .info ("Sleeping for one minute." )
334340 time .sleep (60 )
335341
336- tweet_count , likes_count , retweet_count = likes_rt_user (
337- bot , logger , tweet_count , likes_count , retweet_count
338- )
342+ if no_user :
343+ tweet_count , likes_count , retweet_count = likes_rt_search (
344+ bot , logger , keyword , tweet_count , likes_count , retweet_count
345+ )
346+ else :
347+ tweet_count , likes_count , retweet_count = likes_rt_user (
348+ bot , logger , tweet_count , likes_count , retweet_count
349+ )
339350
340351 # update the values in the database
341352 today = datetime .datetime .today ().strftime ("%Y-%m-%d" )
@@ -379,7 +390,7 @@ def crawl_keyword(bot, logger, keyword):
379390 time .sleep (15 * 60 )
380391 logger .info ("Sleeping for 15 minutes." )
381392 time .sleep (15 * 60 )
382- except twitter . api . TwitterHTTPError as e :
393+ except Exception as e :
383394
384395 if tweet_count != 0 :
385396 db .update_stat (
@@ -438,6 +449,7 @@ def main():
438449 args = (
439450 bot ,
440451 logger ,
452+ args .no_user ,
441453 ),
442454 )
443455 t2 = Thread (target = server .app .run , kwargs = {"host" : "0.0.0.0" })
@@ -454,6 +466,7 @@ def main():
454466 bot ,
455467 logger ,
456468 args .keyword ,
469+ args .no_user ,
457470 ),
458471 )
459472 t2 = Thread (target = server .app .run , kwargs = {"host" : "0.0.0.0" })
0 commit comments