Skip to content

Instantly share code, notes, and snippets.

@macolyte
Created October 13, 2012 12:55
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 macolyte/3884563 to your computer and use it in GitHub Desktop.
Save macolyte/3884563 to your computer and use it in GitHub Desktop.
ADN Follower suggestions
import re, urllib, operator
from collections import defaultdict
USERNAME = raw_input("Get suggestions for: ")
CUTOFF = 3
pattern = re.compile(r'<span class="username"><a href="/\w+">(?P<name>\w+)</a></span>')
suggestions = defaultdict(int)
def find_followers(user):
print "**********"
print "Finding followers for %s" % user
url = "https://alpha.app.net/%s/following/" % user
user_html = urllib.urlopen(url).read()
user_following = re.findall(pattern, user_html)
print "%s follows %d people" % (user, len(user_following))
return user_following
i_follow = find_followers(USERNAME)
n_follow = len(i_follow)
for user in i_follow:
user_following = find_followers(user)
for person in user_following:
if person in i_follow:
continue
else:
suggestions[person] += 1
sorted_suggestions = sorted(suggestions.iteritems(), key=operator.itemgetter(1))
final_suggestions = (item for item in sorted_suggestions if item[1] > CUTOFF)
output = "<html><head></head><body><table border='1'>"
for item in final_suggestions:
percentage = (float(item[1])/n_follow) * 100
output += "<tr><td><a href='https://alpha.app.net/%s/'>%s</td><td>%.1f%%</td></tr>\n" % (item[0], item[0], percentage)
output += "</table></body></html>"
with open("adn_suggestions.html", "w") as f:
f.write(output)
print "\nAll done. Your suggestions are in adn_suggestions.html"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment