The Twitter Weather App averages the weather from the last N number of geotagged tweets.
You will need a subscribe key for pubnub-twitter along with a WeatherAPI key to authenticate your app. Get your keys from the PubNub Twitter Stream Page and your WeatherAPI Account respectively.
If you don't want to copy the code from this document, you can clone the repository and use the files in there.
-
run
pip install -r requirements.txt
-
Create a file named
secrets.py
and set the following constants:TWITTER_SUB_KEY = "<pubnub-twitter-key" WEATHER_API_KEY = "<your_weather_api_key>"
You first need to start the subcribe process to see the updates you want to publish.
-
Open the terminal and run the script with
python3 run_twitter_weather.py -n <number_of_tweets_to_average_over> [-r,--remove_files]
.This will start logging temperatures and the sliding average temperatures in
temps.txt
andsliding_avg_temps_f.txt
, respectively (in fahrenheit).-r
or--remove_files
removes these log files before running. You can also runpython3 run_twitter_weather.py -h
for help.Once started, you should see a message that the script has connected to
pubnub-twitter
and begins to receive tweet messages -
When you're finished, press
Control-C
to exit the script. -
To test whether the script has run properly, run
python3 twitter_weather_test.py -n <SAME_NUMBER_OF_TWEETS_AS_RUN>
without deleting the log files.You should see
Tests passed.
for a successful test run.Sample data has been included in this repo for n=10 Tweets to average over.
If you need help or have a general question, contact rjwgibbs@gmail.com.