in src/plugins/scanners/twitter.py [0:0]
def getFollowers(KibbleBit, source, t):
""" Get followers of a handle, store them for mapping and trend purposes"""
# Get our twitter handle
handle = source['sourceURL']
# Get number of followers
tuser = t.GetUser(screen_name=handle)
no_followers = tuser.followers_count
d = time.strftime("%Y/%m/%d 0:00:00", time.gmtime()) # Today at midnight
dhash = hashlib.sha224((("twitter:%s:%s:%s") % (source['organisation'], source['sourceURL'], d)).encode('ascii', errors='replace')).hexdigest()
jst = {
'organisation': source['organisation'],
'sourceURL': source['sourceURL'],
'sourceID': source['sourceID'],
'id': dhash,
'followers': no_followers,
'date': d
}
KibbleBit.pprint("%s has %u followers currently." % (handle, no_followers))
KibbleBit.index('twitter_followers', dhash, jst)
# Collect list of current followers
followers = t.GetFollowers(screen_name=handle)
# For each follower, if they're not mapped yet, add them
# This has a limitation of 100 new added per run, but meh...
KibbleBit.pprint("Looking up followers of %s" % handle)
for follower in followers:
# id, name, screen_name are useful here
KibbleBit.pprint ("Found %s as follower" % follower.screen_name)
# Store twitter follower profile if not already logged
dhash = hashlib.sha224((("twitter:%s:%s:%s") % (source['organisation'], handle, follower.id)).encode('ascii', errors='replace')).hexdigest()
if not KibbleBit.exists('twitter_follow',dhash):
jst = {
'organisation': source['organisation'],
'sourceURL': source['sourceURL'],
'sourceID': source['sourceID'],
'twitterid': follower.id,
'name': follower.name,
'screenname': follower.screen_name,
'id': dhash,
'date': time.strftime("%Y/%m/%d %H:%M:%S", time.gmtime()) # First time we spotted them following.
}
KibbleBit.pprint("%s is new, recording date and details." % follower.screen_name)
KibbleBit.index('twitter_follow', dhash, jst)