Commits

Anonymous committed 5ca63ee

intial check in

Comments (0)

Files changed (1)

+from BeautifulSoup import BeautifulSoup
+from mechanize import Browser
+import re
+import simplejson as json
+
+FRIEND_TABLE_CLASS = 'XbcProfileTable XbcFriendsListTable'
+GAMER_TAG_CLASS = 'XbcGamerTag'
+GAMER_PRESENCE_CLASS = 'XbcGamerPresence'
+GAMER_STATUS_CLASS = 'XbcGamerDescription'
+
+
+def GetXboxLiveFriends(login, passwd):
+    """Return a list of tuples (gamer_tag, gamer_presence)."""
+    br = Browser()
+    br.open('http://live.xbox.com/en-US/profile/Friends.aspx')
+    br.select_form(name='f1')
+    br['login'] = login
+    br['passwd'] = passwd
+    br.submit()  # Submit login form.
+    br.select_form(name='fmHF')
+    response = br.submit()  # Submit redirect form.
+    friend_list = response.read()
+    response.close()
+
+    f = open('fl.htm', 'w')
+    f.write(friend_list)
+    f.close()
+		
+    soup = BeautifulSoup(friend_list)
+    friend_table = soup.find('table', {'class': FRIEND_TABLE_CLASS})
+    if friend_table is None:
+      raise XboxLiveError('Parsing failure.')
+
+    friends = []
+    for row in friend_table.contents[1:]:  # Skip header row.
+      if(row == "\n"):
+        continue
+
+      gamer_tag = row.find('td', {'class': GAMER_TAG_CLASS})
+      if(gamer_tag == None):
+        continue
+      
+      gamer_tag = str(gamer_tag.find('a').contents[0])
+      gamer_presence = row.find('td', {'class': GAMER_PRESENCE_CLASS})
+      gamer_presence = str(gamer_presence.contents[0]).strip()
+      gamer_status = row.find('td', {'class': GAMER_STATUS_CLASS})
+      gamer_status = str(gamer_status.contents[0]).strip()
+      friends.append((gamer_tag, gamer_presence, gamer_status))
+
+    return friends
+
+fp = open("xli.dat", "r")
+xli = json.load(fp)
+fp.close()
+friends = GetXboxLiveFriends(xli["uname"], xli["passwd"])
+for friend in friends:
+    print friend