forked from maksim2042/SNABook
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added slides, fixed code, cooked dinner, swept the floor...
- Loading branch information
Max
committed
Nov 9, 2011
1 parent
2dd5fcc
commit 4544141
Showing
18 changed files
with
176 additions
and
2 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import tweepy | ||
|
||
# First, the basics | ||
|
||
""" | ||
Consumer key wADh1LqyQCR3OmEGqK3SDg | ||
Consumer secret FzKWL6bMfL6oHvHwh9daANHuSScXua5K386513FbU6c | ||
Request token URL https://api.twitter.com/oauth/request_token | ||
Authorize URL https://api.twitter.com/oauth/authorize | ||
Access token URL https://api.twitter.com/oauth/access_token | ||
Access token 153439378-AuXJgQ8oHmnY0JSabav6kGNoVg5iOB7t9CF3B3cF | ||
Access token secret LKm3AlD0fhCE4ofZXYZALxtsMNBaRqXmJWiTgUT1Jlo | ||
""" | ||
|
||
access_token='153439378-AuXJgQ8oHmnY0JSabav6kGNoVg5iOB7t9CF3B3cF' | ||
access_token_secret='LKm3AlD0fhCE4ofZXYZALxtsMNBaRqXmJWiTgUT1Jlo' | ||
|
||
|
||
def connect(): | ||
auth = tweepy.OAuthHandler("myAuthToken",access_token) | ||
auth.set_access_token("myAccessToken", access_token_secret) | ||
api = tweepy.API(auth) | ||
if api and api.verity_credentials(): | ||
return api | ||
else: | ||
raise "Login failed." | ||
|
||
query = '"someScreenName" OR "#sometag"' # a valid Twitter search query | ||
|
||
def run_search(query = query): | ||
q = { | ||
'q': query, | ||
'lang': 'en', | ||
} | ||
|
||
api = connect() | ||
try: | ||
for status in Cursor(api.search, **q).items(): | ||
process_tweet(status) | ||
except TweepError: | ||
traceback.print_exc() | ||
raise |
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import tweepy | ||
|
||
class MyStreamListener(tweepy.StreamListener): | ||
def on_error(self, status_code): | ||
print 'An error has occured! Status code %s.' % status_code | ||
return True # keep stream alive | ||
|
||
def on_timeout(self): | ||
print 'Snoozing Zzzzzz' | ||
time.sleep(10) | ||
return True | ||
|
||
def on_delete(self, status_id, user_id): | ||
"""Called when a delete notice arrives for a status""" | ||
#print "Delete notice for %s. %s" % (status_id, user_id) | ||
return | ||
|
||
def on_limit(self, track): | ||
"""Called when a limitation notice arrvies""" | ||
print "!!! Limitation notice received: %s" % str(track) | ||
return | ||
|
||
def on_status(self, status): | ||
process_tweet(status) | ||
return True # or False if you want the stream to disconnect | ||
|
||
|
||
def start_stream(username, password, listener, follow=(), track=(): | ||
''' | ||
follow: list of users to follow | ||
track: list of keywords to track | ||
''' | ||
print 'Connecting as %s/%s' % (username, password) | ||
stream = tweepy.Stream(username, password, listener, timeout=60) | ||
if follow or track: | ||
print "Starting filter on %s/%s" % (','.join(follow), ','.join(track)) | ||
stream.filter(follow=follow, track=track, async=True) | ||
else: | ||
print "Starting sample" | ||
stream.sample(async=True) | ||
|
||
# Process a sample stream: | ||
|
||
listener = MyStreamListener() | ||
start_stream("myusername","mypassword",listener) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
>>> len(retweets) | ||
>>> net.draw(retweets) | ||
>>> undir_retweets=retweets.to_undirected() | ||
>>> comps=net.connected_component_subgraphs(undir_retweets) | ||
>>> len(comps) | ||
>>> len(comps[0]) | ||
>>> net.draw(comps[0]) | ||
|
||
degrees=net.degree(comps[0]) | ||
|
||
degrees=sorted_degree(comps[0]) | ||
degrees[:10] | ||
|
||
plot.hist(net.degree(comps[0]).values(),50) | ||
|
||
core=trim_degrees(comps[0]) | ||
|
||
len(core) | ||
2836 | ||
|
||
len(hashtag_net) | ||
1753 | ||
|
||
net.draw(hashtag_net) | ||
|
||
core=net.connected_component_subgraphs(hashtag_net)[0] | ||
net.draw(core) | ||
|
||
core.remove_node('earthquake') | ||
core2=trim_edges(hashtag_net, weight=2) | ||
net.draw(core2) | ||
|
||
core3=trim_edges(hashtag_net, weight=10) | ||
net.draw(core3) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains 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