<commit_before><commit_msg>Add teamstacks -- see who is friends in your game<commit_after>#!/usr/bin/env python
from __future__ import print_function
from re import search, finditer, DOTALL, MULTILINE
from copy import copy
from sys import version_info
if version_info.major >= 3:
    from html.parser import HTMLParser
else:
    from HTMLParser import HTMLParser

from steamweb.steamwebbrowser import SteamWebBrowserCfg

def get_friends(swb, id):
    r = swb.get('http://steamcommunity.com/{id}/friends'.format(id=id))
    return [friend.group(1) for friend in finditer('<a class="friendBlockLinkOverlay" href="http://steamcommunity.com/(.*?)"></a>', r.content)]

swb = SteamWebBrowserCfg()
if not swb.logged_in():
    swb.login()

r = swb.get('http://steamcommunity.com/my/friends/players')
if re.match('http://steamcommunity.com/id/[^/]+/friends/$', r.url):
    raise Exception('Not in game.')

players = []
playerNames = {}
for player in finditer('<a class="friendBlockLinkOverlay" href="http://steamcommunity.com/(.*?)".*?<div>(.*?)<br />', r.content, MULTILINE | DOTALL):
    players.append(player.group(1))
    playerNames[player.group(1)] = player.group(2).strip()
# The player who called the program
player = search('<a href="http://steamcommunity.com/(.*?)" data-miniprofile="\d*">(.*?)</a>', r.content)
players.append(player.group(1))
playerNames[player.group(1)] = player.group(2)

groups = []
for player in players:
    group = set([player])
    for friend in get_friends(swb, player):
        if friend in players:
            group.add(friend)
    groups.append(group)

i = 0
while i < len(groups):
    for player in copy(groups[i]):
        j = 0
        while j < i:
            if player in groups[j]:
                groups[i].update(groups[j])
                del groups[j]
                i -= 1
            j += 1
    i += 1

for group in sorted(groups, key=lambda s: -len(s)):
    names = []
    for player in group:
        names.append(HTMLParser().unescape(playerNames[player]))
    print(names)
{'fraction_non_alphanumeric': 0.15742574257425743, 'fraction_numerical': 0.006435643564356435, 'mean_word_length': 3.451541850220264, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '53588', 'n_tokens_mistral': 674, 'n_tokens_neox': 652, 'n_words': 161}