1010
1111
1212def get_updates (last_updated ):
13- log .debug ('Checking for requests, last updated passed is: {}' . format ( last_updated ) )
13+ log .debug ('Checking for requests, last updated passed is: {last_updated}' )
1414 sleep (UPDATE_PERIOD )
15- response = requests .get (API_BASE + BOT_KEY + ' /getUpdates' , params = {'offset' : last_updated + 1 })
15+ response = requests .get (f" { API_BASE } /getUpdates" , params = {'offset' : last_updated + 1 })
1616 json_response = FALSE_RESPONSE
1717 if response .status_code != 200 :
1818 # wait for a bit, try again
@@ -23,14 +23,14 @@ def get_updates(last_updated):
2323 except ValueError :
2424 sleep (UPDATE_PERIOD * 20 )
2525 get_updates (last_updated )
26- log .info (' received response: {}' . format ( json_response ) )
26+ log .info (f" received response: { json_response } " )
2727 return json_response
2828
2929
3030def post_message (chat_id , text ):
31- log .info ( ' posting {} to {}' . format ( text , chat_id ) )
31+ log .debug ( f" posting { text } to { chat_id } " )
3232 payload = {'chat_id' : chat_id , 'text' : text }
33- requests .post (API_BASE + BOT_KEY + ' /sendMessage' , data = payload )
33+ requests .post (f" { API_BASE } /sendMessage" , data = payload )
3434
3535
3636def handle_incoming_messages (last_updated ):
@@ -49,26 +49,23 @@ def handle_incoming_messages(last_updated):
4949 chat_text = ''
5050 split_chat_text .append (chat_text )
5151 log .debug ('Looks like no chat text was detected... moving on' )
52- try :
53- if 'message' in req :
54- person_id = req ['message' ]['from' ]['id' ]
55- else :
56- person_id = ['edited_message' ]['from' ]['id' ]
57- except KeyError :
58- pass
5952
60- log .info ('Chat text received: {0}' .format (chat_text ))
53+ if 'message' in req :
54+ person_id = req ['message' ]['from' ]['id' ]
55+ else :
56+ person_id = req ['edited_message' ]['from' ]['id' ]
57+
58+ log .info (f"Chat text received: { chat_text } " )
6159 r = re .search ('(source+)(.*)' , chat_text )
6260
6361 if (r is not None and r .group (1 ) == 'source' ):
6462 if r .group (2 ):
6563 sources_dict [person_id ] = r .group (2 )
66- log .debug ('Sources set for {0} to {1}' .format (sources_dict [person_id ], r .group (2 )))
67- post_message (person_id , 'Sources set as {0}!' .format (r .group (2 )))
64+ post_message (person_id , f"Sources set as { r .group (2 )} !" )
6865 else :
6966 post_message (person_id , 'We need a comma separated list of subreddits! No subreddit, no news :-(' )
7067 if chat_text == '/stop' :
71- log .debug (' Added {0 } to skip list' . format ( chat_sender_id ) )
68+ log .debug (f" Added { chat_sender_id } to skip list" )
7269 skip_list .append (chat_sender_id )
7370 post_message (chat_sender_id , "Ok, we won't send you any more messages." )
7471
@@ -95,5 +92,5 @@ def handle_incoming_messages(last_updated):
9592 f .write (str (last_updated ))
9693 States .last_updated = last_updated
9794 log .debug (
98- 'Updated last_updated to {0}' . format ( last_updated ) )
95+ f 'Updated last_updated to { last_updated } ' )
9996 f .close ()
0 commit comments