Look up Steam64 ID

This commit is contained in:
Bradlee Speice 2017-03-19 13:21:04 -04:00
parent 10c3b8dcad
commit 82849bfd14
4 changed files with 34 additions and 3 deletions

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="Python 3.5.2+ (/usr/bin/python3.5)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="Python 3.5.2+ virtualenv at /opt/venvs/scientific" project-jdk-type="Python SDK" />
</project>

View File

@ -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

View File

@ -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'
]
}
)

View File

@ -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)