Update lab1.md

master
Vladimir Protsenko 3 years ago
parent e13eeaa4ef
commit 1b44ec980f

@ -151,13 +151,13 @@ ACCESS_TOKEN_SECRET = "YOUR_ACCESS_TOKEN_SECRET"
class MyStreamListener(tweepy.StreamListener): class MyStreamListener(tweepy.StreamListener):
def on_status(self, status): def on_status(self, status):
f = open('messages.txt' , 'a') with open('messages.txt' , 'a') as f:
f.write ("@{}, сообщение номер {}\n {}\n".format( f.write ("@{}, сообщение номер {}\n {}\n".format(
status.author.screen_name, status.author.screen_name,
status.id_str, status.id_str,
status.text) status.text)
) )
f.close()
print("@{}, сообщение номер {}\n {}\n".format( print("@{}, сообщение номер {}\n {}\n".format(
status.author.screen_name, status.author.screen_name,
status.id_str, status.id_str,
@ -168,7 +168,7 @@ class MyStreamListener(tweepy.StreamListener):
if status_code == 420: if status_code == 420:
return False return False
def monitoring_samara_tweets(query): def monitoring_samara_tweets(api, query=""):
GEOBOX_SAMARA_BIG = [48.9700523344,52.7652295668,50.7251182524,53.6648329274] GEOBOX_SAMARA_BIG = [48.9700523344,52.7652295668,50.7251182524,53.6648329274]
myStreamListener = MyStreamListener() myStreamListener = MyStreamListener()
myStream = tweepy.Stream( myStream = tweepy.Stream(
@ -184,7 +184,7 @@ if __name__ == '__main__':
auth = tweepy.OAuthHandler(API_KEY, API_SECRET) auth = tweepy.OAuthHandler(API_KEY, API_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET) auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth) api = tweepy.API(auth)
monitoring_samara_tweets(query) monitoring_samara_tweets(api, query)
except Exception as error_msg: except Exception as error_msg:
print (error_msg) print (error_msg)
``` ```

Loading…
Cancel
Save