Do you feel alright today? (Final A)
Mapping mood based on Twitter API.
In general, We can easily map a lot of data such as transportation, buildings,meteorology and other economical data. We can do these via Google data , NYC open data or other tangible data, but what if I want to know how do people feel in some specific places? who are they? what happy or sad things are they talking about?
At the same time, I found that people are always using social media like Facebook, twitter to express their feelings. It records their names, locations as well as words. So I started to use twitter.
#Start datamining!
First thing is to get data. There are many tutorials to get Twitter Data. For example, https://www.toptal.com/python/twitter-data-mining-using-python
However, I find an easier way to do it by grasshopper plugin-MOSQUITO. Thanks to Carson Smuts who created it!
In this way, I search for key words “happy” in a circle area of 5km radius near columbus circle, so that I can get nearly 100 Twitter status talking about happy and their users. Finally, I get the CSV file including username,words and the profile url.
By using grids for visualization, we can see who they are and what they are talking interms of “happy”.
#When click the Happy face button of Columbus circle, it should loadimages from CSV file
import csv
def setup():
size(750,400)
background(0)
global urls
urls = []
global usernames
usernames = []
global words
words = []with open(“happycircle.csv”) as f:
reader = csv.reader(f)
header = reader.next() # Skip the header row.
for row in reader:
url = row[5]
username=row[3]
word=row[4]
urls.append(url)
usernames.append(username)
words.append(word)
for row in xrange(6):
for column in xrange(15):
locationY=row*50
locationX=column*50
print row
print column
print row*15+column
print urls[row*15+column]
thumbnail = loadImage(urls[row*15+column])
image(thumbnail,locationX,locationY)def draw():
#pass
#description
text(“People who feel happy in Columbus circle”, 10, 350)
# mouse interactioncountcolumn=floor(mouseX/50)
countrow=floor(mouseY/50)
count=countrow*15+countcolumn
print words[count]
print usernames[count]text(usernames[count], 10,380)
text(“said”,100,380)
text(words[count],150,380)
import spatialpixel.mapping.slippymapper as slippymapper#Set basemap
def setup():
size(1000, 800, P2D)
global nyc
nyc = slippymapper.SlippyMapper(40.746, -73.969, 12, ‘carto-light’, width, height)# Create marker for each spots.
# sample data.
pin = loadImage(“https://s3.amazonaws.com/spatialpixel/maps/map-pin-10px.png")
# This is text for Landmarknyc.addMarker(40.808238, -73.959277, “Columbia University”)
nyc.addMarker(40.758899, -73.987319, “Timesquare”)
nyc.addMarker(40.768048, -73.984561, “Columbus Circle”)
nyc.render()
def draw():
background(255)
nyc.draw()
#this is botton for Columbus circle
img1=loadImage(“happy.png”)
image(img1,440,300)
img2=loadImage(“sad.png”)
image(img2,450,300)#this is button for Timesquare
img3=loadImage(“happy.png”)
image(img3,470,350)
img4=loadImage(“sad.png”)
image(img4,480,350)
#this is button for Columbia university
img5=loadImage(“happy.png”)
image(img3,510,155)
img6=loadImage(“sad.png”)
image(img4,520,155)
#loadimages from CSV file
Finally, we can do more spots and make a map. So we can see people’s happy or sad feelings in different places.
In this way, we can see how people’s feeling vary from places.
Thank you for your reading.