2
2
import requests
3
3
4
4
# Function to get tweets from Twitter API
5
+
6
+
5
7
def get_tweets (api_key , api_secret_key , access_token , access_token_secret , username ):
6
8
auth = tweepy .OAuthHandler (api_key , api_secret_key )
7
9
auth .set_access_token (access_token , access_token_secret )
@@ -13,10 +15,12 @@ def get_tweets(api_key, api_secret_key, access_token, access_token_secret, usern
13
15
tweets .append (tweet .full_text )
14
16
except tweepy .TweepError as e :
15
17
print (f"Error: { e } " )
16
-
18
+
17
19
return tweets
18
20
19
21
# Function to get weather data from OpenWeatherMap API
22
+
23
+
20
24
def get_weather (api_key , city ):
21
25
url = f"http://api.openweathermap.org/data/2.5/weather?q={ city } &appid={ api_key } "
22
26
response = requests .get (url )
@@ -29,6 +33,8 @@ def get_weather(api_key, city):
29
33
return None
30
34
31
35
# Function to get stock data from Alpha Vantage API
36
+
37
+
32
38
def get_stock_data (api_key , symbol ):
33
39
url = f"https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol={ symbol } &apikey={ api_key } "
34
40
response = requests .get (url )
@@ -40,6 +46,7 @@ def get_stock_data(api_key, symbol):
40
46
print (f"Error: { data ['Note' ]} " )
41
47
return None
42
48
49
+
43
50
if __name__ == "__main__" :
44
51
# Replace with your Twitter API credentials
45
52
twitter_api_key = "YOUR_TWITTER_API_KEY"
@@ -57,7 +64,8 @@ def get_stock_data(api_key, symbol):
57
64
stock_symbol = "AAPL"
58
65
59
66
# Retrieve data from APIs
60
- tweets = get_tweets (twitter_api_key , twitter_api_secret_key , twitter_access_token , twitter_access_token_secret , twitter_username )
67
+ tweets = get_tweets (twitter_api_key , twitter_api_secret_key ,
68
+ twitter_access_token , twitter_access_token_secret , twitter_username )
61
69
weather_data = get_weather (weather_api_key , city_name )
62
70
stock_data = get_stock_data (alpha_vantage_api_key , stock_symbol )
63
71
0 commit comments