How to import tweets to CartoDB with Python

I have been quite busy these last couple of weeks. On the 3rd of December I attended to the CartoDBeers and Workshop for data journalists at CartoDB Headquarters to be prepared for the next Spanish general elections. Then on the 5th of this month, Carmen Langa and me organized a kids map workshop at Medialab-Prado. But this requires a whole blog post to explain how much fun we had! Finally, last thursday I went to Campus Madrid at the last stop of the LocationTech Tour. It was quite interesting to listen to all the people from CartoDB, QGIS, Glob3mobile and Boundless.

And in the meantime I manage to figure out how to import tweets from twitter to CartoDB using Python:

A couple of months ago, Paisaje Transversal asked me for programming a script for geolocating, categorizing (according a sentiment analysis)  and visualizing tweets from their events. I have just signed up to the Master in GIS Programming with Python imparted by Geospatial Training Services so I used this task as my final project. And after a lot of try and error, debugging and realizing that people in Spain rarely geolocalize their tweets I came up with three elegant scripts.

I uploaded all three of them plus an example to my twitter2cartodb-with-Python Github repository. In order to get and visualize your tweets you need to follow these steps. First, change the parameters of the scripts according to your goals. Then, run “tweet2csv.py” or “timeline2csv.py” if you want to capture tweets from a past or present event, respectively. Next run the “csv2cartodb.py” script. Finally, you have to create a Torque Cat map in CartoDB. As said in the readme file, you would have needed to get your Twitter and CartoDB API keys and download and install Tweepy (for accessing Twitter API), Geopy (for geocoding), TextBlob (for sentiment analysis) and CartoDB (for accessing CartoDB API) modules. Have a look at the example I attached where the #AccordDeParis was selected as the hashtag of study.

Now it is turn to start analysing real events.

GIS Analyst. Working at @CARTO and @ongawa4d.

0 Comments

  1. Pingback: Mapmaking workshop for kids | Ramiro Aznar

  2. Pingback: Torque visualizations using CartoDB.js | Ramiro Aznar

Leave a Reply

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *