Skip to content

Instantly share code, notes, and snippets.

@starenka
Created August 24, 2011 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save starenka/1169607 to your computer and use it in GitHub Desktop.
Save starenka/1169607 to your computer and use it in GitHub Desktop.
gets common followers stats for twitter accounts
*.pyc
.idea/*
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, itertools
from collections import defaultdict
import tweepy
def wannabe_venn(data, r=0):
r = r if r else len(data.keys())
for v in itertools.combinations(data.keys(), r):
vsets = [data[x] for x in v]
yield tuple(sorted(v)), reduce(lambda x, y: x.intersection(y), vsets),
if len(sys.argv) < 3:
sys.exit('Pass at least two @accounts seperated by space')
data = defaultdict(set)
for account in sys.argv[1:]:
print '+ getting %s\'s followers count' % account
try:
data[account] = set(tweepy.API().followers_ids(account))
print '+ "%s" has %d followers' % (account, len(data[account]))
except tweepy.error.TweepError:
sys.exit('- Failed to get %s followers count. Typo in account name maybe?'%account)
for r in range(2, len(data.keys()) + 1):
for accounts, common in wannabe_venn(data, r):
uniq = len(set(itertools.chain.from_iterable([(data[acc]) for acc in accounts])))
ratio = float(len(common)) / uniq * 100
print '= %s have %d common followers out of %d, which is approx %f%%' %\
(' AND '.join(accounts), len(common), uniq, ratio)
@starenka
Copy link
Author

starenka@kosmik1:/data/prac/python/twinsects$ ./twinsects.py starenka benabraham fczbkk kvbik

  • getting starenka's followers count
  • "starenka" has 701 followers
  • getting benabraham's followers count
  • "benabraham" has 287 followers
  • getting fczbkk's followers count
  • "fczbkk" has 536 followers
  • getting kvbik's followers count
  • "kvbik" has 205 followers
    = kvbik AND starenka have 33 common followers out of 873, which is approx 3.780069%
    = fczbkk AND starenka have 112 common followers out of 1125, which is approx 9.955556%
    = benabraham AND starenka have 60 common followers out of 928, which is approx 6.465517%
    = fczbkk AND kvbik have 51 common followers out of 690, which is approx 7.391304%
    = benabraham AND kvbik have 41 common followers out of 451, which is approx 9.090909%
    = benabraham AND fczbkk have 91 common followers out of 732, which is approx 12.431694%
    = fczbkk AND kvbik AND starenka have 19 common followers out of 1265, which is approx 1.501976%
    = benabraham AND kvbik AND starenka have 13 common followers out of 1072, which is approx 1.212687%
    = benabraham AND fczbkk AND starenka have 31 common followers out of 1292, which is approx 2.399381%
    = benabraham AND fczbkk AND kvbik have 28 common followers out of 873, which is approx 3.207331%
    = benabraham AND fczbkk AND kvbik AND starenka have 11 common followers out of 1421, which is approx 0.774103%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment