From 1b44ec980fe93975e939762c29084e69d7b03b70 Mon Sep 17 00:00:00 2001 From: Vladimir Protsenko Date: Tue, 7 Sep 2021 10:25:45 +0000 Subject: [PATCH] Update lab1.md --- lab1.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lab1.md b/lab1.md index a1af94b..fb43edc 100644 --- a/lab1.md +++ b/lab1.md @@ -151,13 +151,13 @@ ACCESS_TOKEN_SECRET = "YOUR_ACCESS_TOKEN_SECRET" class MyStreamListener(tweepy.StreamListener): def on_status(self, status): - f = open('messages.txt' , 'a') - f.write ("@{}, сообщение номер {}\n {}\n".format( - status.author.screen_name, - status.id_str, - status.text) - ) - f.close() + with open('messages.txt' , 'a') as f: + f.write ("@{}, сообщение номер {}\n {}\n".format( + status.author.screen_name, + status.id_str, + status.text) + ) + print("@{}, сообщение номер {}\n {}\n".format( status.author.screen_name, status.id_str, @@ -168,7 +168,7 @@ class MyStreamListener(tweepy.StreamListener): if status_code == 420: return False -def monitoring_samara_tweets(query): +def monitoring_samara_tweets(api, query=""): GEOBOX_SAMARA_BIG = [48.9700523344,52.7652295668,50.7251182524,53.6648329274] myStreamListener = MyStreamListener() myStream = tweepy.Stream( @@ -184,7 +184,7 @@ if __name__ == '__main__': auth = tweepy.OAuthHandler(API_KEY, API_SECRET) auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET) api = tweepy.API(auth) - monitoring_samara_tweets(query) + monitoring_samara_tweets(api, query) except Exception as error_msg: print (error_msg) ```