22import requests
33
44# Function to get tweets from Twitter API
5+
6+
57def get_tweets (api_key , api_secret_key , access_token , access_token_secret , username ):
68 auth = tweepy .OAuthHandler (api_key , api_secret_key )
79 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
1315 tweets .append (tweet .full_text )
1416 except tweepy .TweepError as e :
1517 print (f"Error: { e } " )
16-
18+
1719 return tweets
1820
1921# Function to get weather data from OpenWeatherMap API
22+
23+
2024def get_weather (api_key , city ):
2125 url = f"http://api.openweathermap.org/data/2.5/weather?q={ city } &appid={ api_key } "
2226 response = requests .get (url )
@@ -29,6 +33,8 @@ def get_weather(api_key, city):
2933 return None
3034
3135# Function to get stock data from Alpha Vantage API
36+
37+
3238def get_stock_data (api_key , symbol ):
3339 url = f"https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol={ symbol } &apikey={ api_key } "
3440 response = requests .get (url )
@@ -40,6 +46,7 @@ def get_stock_data(api_key, symbol):
4046 print (f"Error: { data ['Note' ]} " )
4147 return None
4248
49+
4350if __name__ == "__main__" :
4451 # Replace with your Twitter API credentials
4552 twitter_api_key = "YOUR_TWITTER_API_KEY"
@@ -57,7 +64,8 @@ def get_stock_data(api_key, symbol):
5764 stock_symbol = "AAPL"
5865
5966 # 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 )
6169 weather_data = get_weather (weather_api_key , city_name )
6270 stock_data = get_stock_data (alpha_vantage_api_key , stock_symbol )
6371
0 commit comments