Beispiel #1
0
    def get_web_session(self, language='english'):
        """Get a :class:`requests.Session` that is ready for use

        See :meth:`get_web_session_cookies`

        .. note::
            Auth cookies will only be send to ``(help|store).steampowered.com`` and ``steamcommunity.com`` domains

        :param language: localization language for steam pages
        :type language: :class:`str`
        :return: authenticated Session ready for use
        :rtype: :class:`requests.Session`, :class:`None`
        """
        cookies = self.get_web_session_cookies()
        if cookies is None:
            return None

        session = make_requests_session()

        for domain in ['store.steampowered.com', 'help.steampowered.com', 'steamcommunity.com']:
            for name, val in cookies.items():
                secure = (name == 'steamLoginSecure')
                session.cookies.set(name, val, domain=domain, secure=secure)

            session.cookies.set('Steam_Language', language, domain=domain)
            session.cookies.set('birthtime', '-3333', domain=domain)

        return session
Beispiel #2
0
def steam64_from_url(url, http_timeout=30):
    """
    Takes a Steam Community url and returns steam64 or None

    .. note::
        Each call makes a http request to ``steamcommunity.com``

    .. note::
        For a reliable resolving of vanity urls use ``ISteamUser.ResolveVanityURL`` web api

    :param url: steam community url
    :type url: :class:`str`
    :param http_timeout: how long to wait on http request before turning ``None``
    :type http_timeout: :class:`int`
    :return: steam64, or ``None`` if ``steamcommunity.com`` is down
    :rtype: :class:`int` or :class:`None`

    Example URLs::

        https://steamcommunity.com/gid/[g:1:4]
        https://steamcommunity.com/gid/103582791429521412
        https://steamcommunity.com/groups/Valve
        https://steamcommunity.com/profiles/[U:1:12]
        https://steamcommunity.com/profiles/76561197960265740
        https://steamcommunity.com/id/johnc
    """

    match = re.match(r'^(?P<clean_url>https?://steamcommunity.com/'
                     r'(?P<type>profiles|id|gid|groups)/(?P<value>.*?))(?:/(?:.*)?)?$', url)

    if not match:
        return None

    web = make_requests_session()

    try:
        # user profiles
        if match.group('type') in ('id', 'profiles'):
            text = web.get(match.group('clean_url'), timeout=http_timeout).text
            data_match = re.search("g_rgProfileData = (?P<json>{.*?});[ \t\r]*\n", text)

            if data_match:
                data = json.loads(data_match.group('json'))
                return int(data['steamid'])
        # group profiles
        else:
            text = web.get(match.group('clean_url'), timeout=http_timeout).text
            data_match = re.search("'steam://friends/joinchat/(?P<steamid>\d+)'", text)

            if data_match:
                return int(data_match.group('steamid'))
    except requests.exceptions.RequestException:
        return None
Beispiel #3
0
def steam64_from_url(url, http_timeout=30):
    """
    Takes a Steam Community url and returns steam64 or None

    .. note::
        Each call makes a http request to ``steamcommunity.com``

    .. note::
        For a reliable resolving of vanity urls use ``ISteamUser.ResolveVanityURL`` web api

    :param url: steam community url
    :type url: :class:`str`
    :param http_timeout: how long to wait on http request before turning ``None``
    :type http_timeout: :class:`int`
    :return: steam64, or ``None`` if ``steamcommunity.com`` is down
    :rtype: :class:`int` or :class:`None`

    Example URLs::

        https://steamcommunity.com/gid/[g:1:4]
        https://steamcommunity.com/gid/103582791429521412
        https://steamcommunity.com/groups/Valve
        https://steamcommunity.com/profiles/[U:1:12]
        https://steamcommunity.com/profiles/76561197960265740
        https://steamcommunity.com/id/johnc
    """

    match = re.match(r'^https?://steamcommunity.com/'
                     r'(?P<type>profiles|id|gid|groups)/(?P<value>.*)/?$', url)

    if not match:
        return None

    url = re.sub(r'^https', 'http', url)  # avoid 1 extra req, https is redirected to http anyway
    web = make_requests_session()
    nocache = time() * 100000

    try:
        if match.group('type') in ('id', 'profiles'):
            xml = web.get("%s/?xml=1&nocache=%d" % (url, nocache), timeout=http_timeout).text
            match = re.findall('<steamID64>(\d+)</steamID64>', xml)
        else:
            xml = web.get("%s/memberslistxml/?xml=1&nocache=%d" % (url, nocache), timeout=http_timeout).text
            match = re.findall('<groupID64>(\d+)</groupID64>', xml)
    except requests.exceptions.RequestException:
        return None

    if not match:
        return None

    return match[0]  # return matched steam64
Beispiel #4
0
 def __init__(self, username, password):
     self.__dict__.update(locals())
     self.session = make_requests_session()
     self._session_setup()
Beispiel #5
0
 def test_make_requests_session(self):
     self.assertIsInstance(uweb.make_requests_session(), requests.Session)
Beispiel #6
0
 def __init__(self, username, password=''):
     self.__dict__.update(locals())
     self.session = make_requests_session()
     self._session_setup()
Beispiel #7
0
 def test_make_requests_session(self):
     self.assertIsInstance(uweb.make_requests_session(), requests.Session)