-
Notifications
You must be signed in to change notification settings - Fork 0
/
livefeed.py
executable file
·73 lines (50 loc) · 1.84 KB
/
livefeed.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python
#-----------------------------------------------------------------------
# twitter-authorize:
# - step through the process of creating and authorization a
# Twitter application.
#-----------------------------------------------------------------------
import tweepy
import time
import json
import sys
import fileinput
import re
import cgi
import urllib2
data = json.load(urllib2.urlopen('https://boiling-inferno-993.firebaseio.com/hashtag.json'))
form = cgi.FieldStorage()
searchterm = form.getvalue('searchbox')
auth = tweepy.OAuthHandler("EKbYg6CUbKQRvVqfr0mVgbFq6", "qG9hnE8HtzbLBxBeynUEaWLdZdEt6pIGaZJLNiDIa21wz2ngd5")
auth.set_access_token("703518623701164032-zOf5QwEgVFmV58QW67qqqbojwYWDGan", "bumLD5Vq1uaBi55Uv47vKFLRmJvtYj6i0NgfFmxgfHmIe")
api = tweepy.API(auth)
word_counts = {}
PRINT_FREQUENCY = 5
MIN_WORD_LENGTH = 3
PUNCTUATION = [".", ",", "/", "#", "@", "(", ")"]
most_popular = []
def print_word_counts():
ordered_word_counts = sorted(word_counts.items(), key=lambda x: x[1], reverse=True)
f = open("/Users/George/documents/WhoseTalking/WTwebsite/files.txt", 'w')
for word,count in ordered_word_counts[:20]:
word = word.encode('utf-8')
#print count, "\t", word
f.write(str(count) + "\t" + word + "\n")
f.close()
#livestream
class MyStreamListener(tweepy.StreamListener):
def on_status(self, tweet):
description = tweet.user.description or ''
for separator in PUNCTUATION:
description = description.replace(separator, " ")
words = description.lower().split()
for word in words:
if len(word) > MIN_WORD_LENGTH:
if word in word_counts:
word_counts[word] += 1
else:
word_counts[word] = 1
print_word_counts()
myStreamListener = MyStreamListener()
myStream = tweepy.Stream(auth = api.auth, listener=MyStreamListener())
myStream.filter(track=[data])