-
-
Save Zulko/f8735acf94cc97d6c53d to your computer and use it in GitHub Desktop.
Revisions
-
Zulko revised this gist
Aug 22, 2014 . 1 changed file with 10 additions and 13 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,23 +1,20 @@ ''' Rewrite with Twittcher ;) Result (every 20 seconds): >>> Most common words: [('ferguson', 41), ('http', 28), ('protests', 9), ('missouri', 9), ('leave', 8), ('continue', 8),...] ''' import re from collections import Counter from twittcher import SearchWatcher counter = Counter() def action(tweet): words = [w for w in re.findall("\w+",tweet.text) if len(w)>3] counter.update([w.lower() for w in words]) print ("Most common words: %s"%(counter.most_common(20))) bot = SearchWatcher("ferguson", action=action) bot.watch_every(20) # 20 seconds -
Zulko revised this gist
Aug 21, 2014 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,8 @@ ''' Rewrite with Twittcher ;) The result looks like this at every occurence: >>> ('Found one ! Current count:', {'teargas': 0, 'camera': 12, 'racist': 28, 'rifle': 4, 'white': 66, 'milk': 1}) ''' from twittcher import SearchWatcher -
Zulko revised this gist
Aug 21, 2014 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,7 @@ ''' Rewrite with Twittcher ;) The result looks like this at every occurence: >>> ('Found one ! Current count:', {'teargas': 0, 'camera': 12, 'racist': 28, 'rifle': 4, 'white': 66, 'milk': 1}) ''' from twittcher import SearchWatcher -
Zulko revised this gist
Aug 21, 2014 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,7 @@ ''' Rewrite with Twittcher ;) ''' from twittcher import SearchWatcher watched_words = ["racist", "white", "teargas", "rifle", "camera", "milk"] -
Zulko revised this gist
Aug 21, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ ''' Rewrite with Twittcher ;) (Not tested) ''' from twittcher import SearchWatcher watched_words = ["racist", "white", "teargas", "rifle", "camera", "milk"] wordcounts = {word:0 for word in watched_words} -
Zulko revised this gist
Aug 21, 2014 . 1 changed file with 14 additions and 66 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,71 +1,19 @@ ''' Rewrite with Twittcher ;) (Not tested) ''' import twittcher watched_words = ["racist", "white", "teargas", "rifle", "camera", "milk"] wordcounts = {word:0 for word in watched_words} def action(tweet): found_at_least_one = False for word in watched_words: if word in tweet.text: wordcounts[word] += 1 found_at_least_one = True if found_at_least_one: print( "Found one ! Current count:", wordcounts) bot = SearchWatcher("ferguson", action=action) bot.watch_every(20) -
howdydoody123 revised this gist
Aug 21, 2014 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -63,6 +63,7 @@ def on_status(self, status): print 'number with \'loot\' is %d' % self.loot print '--------------------------------' if __name__ == '__main__': auth = get_api() l = CustomStreamListener() -
howdydoody123 revised this gist
Aug 21, 2014 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ def get_api(): ''' Creates an instance of the tweepy OAuth class ''' with open('config') as f: api_key = f.readline().strip() @@ -18,6 +18,10 @@ def get_api(): class CustomStreamListener(tweepy.StreamListener): ''' Sub class of StreamListener to handle searching Ferguson tweets for various keywords ''' count = 0 racist = 0 white = 0 -
howdydoody123 revised this gist
Aug 21, 2014 . 1 changed file with 1 addition and 10 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -61,15 +61,6 @@ def on_status(self, status): if __name__ == '__main__': auth = get_api() l = CustomStreamListener() streaming_api = tweepy.Stream(auth, l) streaming_api.filter(track=['Ferguson']) -
howdydoody123 created this gist
Aug 21, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,75 @@ ''' A script for analyzing twitter stats on Ferguson ''' import tweepy def get_api(): ''' Creates an instance of the tweepy API class ''' with open('config') as f: api_key = f.readline().strip() api_secret = f.readline().strip() access_token = f.readline().strip() access_token_secret = f.readline().strip() auth = tweepy.OAuthHandler(api_key, api_secret) auth.set_access_token(access_token, access_token_secret) return auth class CustomStreamListener(tweepy.StreamListener): count = 0 racist = 0 white = 0 ftp = 0 teargas = 0 rifle = 0 camera = 0 milk = 0 loot = 0 def on_status(self, status): self.count += 1 lowered = status.text.lower() if 'racist' in lowered: self.racist += 1 if 'white' in lowered: self.white += 1 if 'ftp' in lowered: self.ftp += 1 if 'tear gas' in lowered: self.teargas += 1 if 'rifle' in lowered: self.rifle += 1 if 'camera' in lowered: self.camera += 1 if 'milk' in lowered: self.milk += 1 if 'loot' in lowered: self.loot += 1 print '----------GOT A TWEET-----------' print 'total is %d' % self.count print 'number with \'racist\' is %d' % self.racist print 'number with \'white\' is %d' % self.white print 'number with \'ftp\' is %d' % self.ftp print 'number with \'tear gas\' is %d' % self.teargas print 'number with \'rifle\' is %d' % self.rifle print 'number with \'camera\' is %d' % self.camera print 'number with \'milk\' is %d' % self.milk print 'number with \'loot\' is %d' % self.loot print '--------------------------------' if __name__ == '__main__': auth = get_api() # api = tweepy.API(auth) l = CustomStreamListener() streaming_api = tweepy.Stream(auth, l) streaming_api.filter(track=['Ferguson']) # result = api.search('#Ferguson', count=100) # print len(result) # count = 0 # for tweet in result: # lowered = tweet.text.lower() # if 'racism' in lowered: # count += 1 # print count