diff --git a/.idea/misc.xml b/.idea/misc.xml index 3e2aac3..4362346 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/playwithfriends/steam.py b/playwithfriends/steam.py index 8c3a394..7659559 100644 --- a/playwithfriends/steam.py +++ b/playwithfriends/steam.py @@ -3,6 +3,7 @@ from enum import Enum from os import path from copy import deepcopy import logging +from bs4 import BeautifulSoup _base_url = 'http://api.steampowered.com' @@ -106,3 +107,21 @@ class SteamAPI(object): 'steamids': steam_id } ) + + def get_steam64_id(self, profile_url): + """ + Get the Steam64 ID for a user, given their profile URL. + This is by far and above the mostly likely piece of code + to break, be careful in the future. + + :param profile_url: Steam community profile URL + :type profile_url: str + :return: Steam64 ID + :rtype: str + """ + profile_html = requests.get(profile_url) + + soup = BeautifulSoup(profile_html.content, 'lxml') + comment_paging = soup.find('div', {'class': 'commentthread_paging'}) + steamid = comment_paging.attrs['id'].split('_')[2] + return steamid diff --git a/setup.py b/setup.py index 162ef59..5964051 100644 --- a/setup.py +++ b/setup.py @@ -10,9 +10,15 @@ setup( packages=find_packages(), install_requires=[ 'requests >= 2.10.0', - 'bottle >= 0.12.7' + 'bottle >= 0.12.7', + 'BeautifulSoup4 >= 3.2.1' ], author='Bradlee Speice', author_email='bradlee.speice@gmail.com', - description='Figure out what games you and your friends should play' + description='Figure out what games you and your friends should play', + entry_points={ + 'console_scripts': [ + 'playwithfriends = playwithfriends.server:main' + ] + } ) diff --git a/tests/test_steam.py b/tests/test_steam.py index 23b8e6c..6423615 100644 --- a/tests/test_steam.py +++ b/tests/test_steam.py @@ -19,3 +19,9 @@ class SteamTest(TestCase): steam_id = '76561198020882912' games = steam.SteamAPI().get_recent_games(steam_id) self.assertTrue(len(games) > 0) + + def test_my_profile_id(self): + profile_url = 'http://steamcommunity.com/id/fractalize/' + steam_id = '76561198020882912' + + self.assertEqual(steam.SteamAPI().get_steam64_id(profile_url), steam_id)