@@ -42,11 +42,7 @@ def help(self, update, context):
4242 def display_tweet (self , context ):
4343 job = context .job
4444 global KILL_SIGNAL
45- if self .level == logging .CRITICAL or self .level == logging .WARNING :
46- with open (self .dirpath + "results.log" , "a" ) as fp :
47- fp .write (time .strftime ("%Y-%m-%d %I:%M:%S %p" ) + ',' + ' INFO ' + 'Telegram_Bot '
48- + 'starting display parameter' + '\n ' )
49- self .nw_logger .logger ('Telegram_Bot starting display parameter' , 'info' , 'Results' )
45+ self .tw_bot .nawab_log ('starting display parameter' , 'info' , 'Telegram_Bot ' )
5046
5147 # the previous date from which the tweets need to be sent
5248 previous_date = self .tw_bot .nawab_find_prev_date ()
@@ -61,13 +57,8 @@ def display_tweet(self, context):
6157 u = self .twitter_api .get_status (id = tid_store ['Id' ])
6258 username = u .author .screen_name
6359 except tweepy .TweepError as e :
64- if self .level == logging .CRITICAL :
65- with open (self .dirpath + "error.log" , "a" ) as fp :
66- fp .write (time .strftime ("%Y-%m-%d %I:%M:%S %p" ) + ',' + ' ERROR ' + 'Telegram_Bot ' +
67- "Tweepy failed to get the status of the user from the " +
68- str (tid_store ['Id' ]) + ' because of ' + e .reason + "\n " )
69- self .nw_logger .logger ('Telegram_Bot Tweepy failed to get the status of the user from the ' +
70- str (tid_store ['Id' ]) + ' because of ' + e .reason , 'error' , 'Error' )
60+ self .tw_bot .nawab_log ('Tweepy failed to get the status of the user from the ' +
61+ str (tid_store ['Id' ]) + ' because of ' + e .reason , 'error' , 'Telegram_Bot ' )
7162 pass
7263 url = 'https://twitter.com/' + \
7364 username + '/status/' + str (tid_store ['Id' ])
@@ -100,11 +91,7 @@ def start(self, update, context):
10091 self .display_tweet , 2 , context = chat_id )
10192 context .chat_data ['job' ] = new_job
10293 update .message .reply_text ('Successfully started!' )
103- if self .level == logging .CRITICAL or self .level == logging .WARNING :
104- with open (self .dirpath + "results.log" , "a" ) as fp :
105- fp .write (time .strftime ("%Y-%m-%d %I:%M:%S %p" ) + ',' + ' INFO ' + 'Telegram_Bot '
106- + 'new job ' + str (new_job ) + '\n ' )
107- self .nw_logger .logger ('Telegram_Bot new job ' + str (new_job ) , 'info' , 'Results' )
94+ self .tw_bot .nawab_log ('new job ' + str (new_job ), 'info' , 'Telegram_Bot ' )
10895 except (IndexError , ValueError ):
10996 update .message .reply_text ('Did you /start yet?' )
11097
@@ -118,25 +105,15 @@ def button(self, update, context):
118105 try :
119106 self .twitter_api .retweet (data )
120107 except tweepy .TweepError as e :
121-
122- if self .level == logging .CRITICAL :
123- with open (self .dirpath + "error.log" , "a" ) as fp :
124- fp .write (time .strftime ("%Y-%m-%d %I:%M:%S %p" ) + ',' + ' ERROR ' + 'Telegram_Bot '
125- + "Tweepy failed to retweet after reading from the store of id " +
126- str (data ) + ' because of ' + e .reason + "\n " )
127-
128- self .nw_logger .logger ('Telegram_Bot' + ' Tweepy failed to retweet after reading from the store of id ' +
129- str (data ) + ' because of ' + e .reason , 'error' , 'Error' )
108+ self .tw_bot .nawab_log ('Tweepy failed to retweet after reading from the store of id ' +
109+ str (data ) + ' because of ' + e .reason , 'error' , 'Telegram_Bot ' )
130110 pass
131111 try :
132112 u = self .twitter_api .get_status (id = int (data ))
133113 username = u .author .screen_name
134114 except tweepy .TweepError as e :
135- fp .write (time .strftime ("%Y-%m-%d %I:%M:%S %p" ) + ',' + ' ERROR ' + 'Telegram_Bot ' +
136- "Tweepy failed to get the status of the user from the " +
137- str (data ) + ' because of ' + e .reason + '\n ' )
138- self .nw_logger .logger ('Telegram_Bot' + ' Tweepy failed to get the status of the user from the ' +
139- str (data ) + ' because of ' + e .reason , 'error' , 'Error' )
115+ self .tw_bot .nawab_log ('Tweepy failed to get the status of the user from the ' +
116+ str (data ) + ' because of ' + e .reason , 'error' , 'Telegram_Bot ' )
140117 pass
141118 url = 'https://twitter.com/' + \
142119 username + '/status/' + str (data )
@@ -150,12 +127,7 @@ def error(self, update, context):
150127 """
151128 Log Errors caused by Updates.
152129 """
153- if self .level == logging .CRITICAL :
154- with open (self .dirpath + "error.log" , "a" ) as fp :
155- fp .write ( time .strftime ("%Y-%m-%d %I:%M:%S %p" ) + ',' + ' ERROR ' + 'Telegram_Bot ' +
156- 'Update ' + update + ' caused error ' + context .error + '\n ' )
157- self .nw_logger .logger ('Telegram_Bot' +
158- ' Update' + update + 'caused error ' + context .error , 'error' , 'Error' )
130+ self .tw_bot .nawab_log ('Update' + update + 'caused error ' + context .error , 'error' , 'Telegram_Bot ' )
159131
160132 def stop (self , update , context ):
161133 if 'job' not in context .chat_data :
0 commit comments