This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import sys | |
import json | |
import time | |
import requests | |
# Get your client ID and secret by creating an App at https://dev.netatmo.com/ | |
NETATMO_CLIENT_ID = "" | |
NETATMO_CLIENT_SECRET = "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Count the number of occurrences for each hashtag, | |
# by first extracting the hashtag and lowercasing it, | |
# then do a standard word count with map and reduceByKey | |
countsRDD = (filteredTweetsRDD | |
.flatMap(lambda tweet: [hashtag['text'].lower() for hashtag in tweet['entities']['hashtags']]) | |
.map(lambda tag: (tag, 1)) | |
.reduceByKey(lambda a, b: a + b) | |
) | |
# Get the most used hashtags (order countsRDD descending by count) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Extract tweets from MongoDB | |
allTweets = [] | |
for doc in db.tweets.find(): | |
allTweets.append(doc['tweet']) | |
# Load tweets into Spark for analysis | |
allTweetsRDD = sc.parallelize(allTweets, 8) | |
# Set up filter to only get tweets from the last week | |
DAYS_LIMIT=7 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get details about own user | |
me = api.me() | |
friends = api.friends_ids(me.id) | |
# Initialize data structure | |
tweets = {} | |
# Fetch lists recent tweets for each of the user IDs in the list 'friends' | |
for user in friends: | |
# Only query Twitter for data not already cached |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#cloud-config | |
packages: | |
- apache2 | |
runcmd: | |
- [ a2ensite, "000-default" ] |