mirror of
https://github.com/balkian/TwitterDigger.git
synced 2024-11-22 08:12:28 +00:00
Can add a custom center for the network
This commit is contained in:
parent
ec0b81bec0
commit
36cd334b2e
51
myego.py
51
myego.py
@ -5,23 +5,32 @@ import shelve
|
|||||||
import math
|
import math
|
||||||
import signal
|
import signal
|
||||||
import sys
|
import sys
|
||||||
|
import argparse
|
||||||
from twitter import Twitter, OAuth, TwitterHTTPError
|
from twitter import Twitter, OAuth, TwitterHTTPError
|
||||||
from httplib import IncompleteRead
|
from httplib import IncompleteRead
|
||||||
|
|
||||||
sh = shelve.open('twits_shelf.db',writeback=True)
|
parser = argparse.ArgumentParser(description='Get an ego network for a given ID.')
|
||||||
keys=['followers','names','distance','userobject']
|
|
||||||
|
parser.add_argument('NAME', nargs='?', metavar='id',
|
||||||
|
default='me', type=str, help='Name of the user to be used as a center')
|
||||||
|
|
||||||
|
parser.add_argument('--new','-n',action='store_true', help='Start a new search.')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
print args.new
|
||||||
|
print args.NAME
|
||||||
|
|
||||||
|
sh = shelve.open('twits_shelf-%s.db' % args.NAME,writeback=True)
|
||||||
|
keys=['followers','distance','userobject']
|
||||||
|
|
||||||
for key in keys:
|
for key in keys:
|
||||||
if key not in sh:
|
if key not in sh or args.new:
|
||||||
sh[key]={}
|
sh[key]={}
|
||||||
|
|
||||||
if 'pending' not in sh:
|
|
||||||
sh['pending']=set()
|
|
||||||
|
|
||||||
followers = sh['followers']
|
followers = sh['followers']
|
||||||
names = sh['names']
|
|
||||||
distance = sh['distance']
|
distance = sh['distance']
|
||||||
pending = sh['pending']
|
pending = set()
|
||||||
userobject = sh['userobject']
|
userobject = sh['userobject']
|
||||||
|
|
||||||
t = Twitter(auth=OAuth(credentials.ACCESS_TOKEN,
|
t = Twitter(auth=OAuth(credentials.ACCESS_TOKEN,
|
||||||
@ -29,11 +38,26 @@ t = Twitter(auth=OAuth(credentials.ACCESS_TOKEN,
|
|||||||
credentials.CONSUMER_KEY,
|
credentials.CONSUMER_KEY,
|
||||||
credentials.CONSUMER_SECRET))
|
credentials.CONSUMER_SECRET))
|
||||||
|
|
||||||
creds = t.account.verify_credentials()
|
if not args.new:
|
||||||
myid = creds['id']
|
print 'Recovering state.'
|
||||||
names[myid] = creds['screen_name']
|
for key in followers:
|
||||||
distance[myid] = 0
|
for follower in followers[key]:
|
||||||
pending.add(myid)
|
if follower not in followers:
|
||||||
|
pending.add(follower)
|
||||||
|
|
||||||
|
if args.new or len(pending)<1:
|
||||||
|
if args.NAME != 'me':
|
||||||
|
user = t.users.lookup(screen_name=args.NAME)[0]
|
||||||
|
uid = user['id']
|
||||||
|
distance[uid] = 0
|
||||||
|
pending.add(uid)
|
||||||
|
else:
|
||||||
|
creds = t.account.verify_credentials()
|
||||||
|
myid = creds['id']
|
||||||
|
distance[myid]=0
|
||||||
|
pending.add(myid)
|
||||||
|
|
||||||
|
print 'Pending is now: %s' %pending
|
||||||
|
|
||||||
def getinfo(piece):
|
def getinfo(piece):
|
||||||
piecestr = ",".join(map(str,piece)) if type(piece) != str and len(piece)>1 else piece[0]
|
piecestr = ",".join(map(str,piece)) if type(piece) != str and len(piece)>1 else piece[0]
|
||||||
@ -66,7 +90,6 @@ def explore_user(t,uid):
|
|||||||
pending.add(follo)
|
pending.add(follo)
|
||||||
distance[follo] = newdist
|
distance[follo] = newdist
|
||||||
|
|
||||||
|
|
||||||
def signal_handler(signal, frame):
|
def signal_handler(signal, frame):
|
||||||
print 'You pressed Ctrl+C!'
|
print 'You pressed Ctrl+C!'
|
||||||
sh.close()
|
sh.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user