2017-11-07 6 views
-3

나는 증기 ID를 얻고 특정 사용자가 그의 도서관에서 가지고있는 게임을 돌려 보내는 python 프로그램을 창조하는 것을 시도하고있다. 나는 온라인으로 검색했고 파이썬에 대해서는 아무것도 발견하지 못했다.
제발 도와 주실 수 있습니까?증기 id에서 증기 게임을 얻으십시오

+1

: 당신이 코드가 있습니까? –

+1

* 무엇을 * 당신이 찾았나요? 다른 언어로 작성된 코드가 있다면 문제는 번역이 아니라 연구 중 하나입니다. – Prune

+0

질문에 steam ink + id의 샘플을 작성하십시오. – DRPK

답변

0

이 시도 (! 내가 완전히 ERROR_HANDLING와 함께 당신을위한 클래스를 작성, 당신은 BeautifulSoup로이 코드보다 효율적으로 ... 또는 다른 패키지를 (개인 사용자에 대해 작동하지 않습니다) 쓸 수 있습니다) :

import requests, json 


class SteamGameGrabber(object): 

    def __init__(self): 

     self.url = '' 
     self.headers = { 
      'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'} 
     self.start_tag = "var rgGames" 
     self.end_tag = "var rgChangingGames" 

     self.last_data = {} 

    def send_request(self): 

     try: 
      response = requests.get(self.url, headers=self.headers) 
      raw_data = str(response.content, encoding="utf-8") 
     except: 
      return [False, "Something Wrong! Connection Lost!"] 

     else: 
      if response.status_code == 200: 
       return [True, raw_data] 
      else: 
       return [False, "Check Your Connection (status_code is Not 200)!"] 

    def pars_data(self, get_input): 

     def find_between(s, first, last): 

      try: 
       start = s.index(first) + len(first) 
       end = s.index(last, start) 
      except: 
       return [False, "Parsing Error"] 
      else: 
       return [True, s[start:end]] 

     if "<title>Steam Community :: Error</title>" in get_input: 
      return [False, "I Can Not Find This ID on Steam Server"] 

     if '<div class="profile_private_info">' in get_input: 
      return [False, "This profile is private, I can not Decode it, sorry."] 

     get_data = find_between(get_input, self.start_tag, self.end_tag) 

     if get_data[0] is True: 

      dict_data = json.loads(get_data[1].strip().lstrip("=").rstrip(";").strip()) 

      try: 
       for box in dict_data: 

        game_id = str(box['appid']).strip() 
        game_name = box['name'].strip() 

        if game_name in self.last_data: 
         pass 

        else: 

         self.last_data[game_name] = game_id 
      except: 
       return [False, "Format is Wrong"] 

      else: 
       return [True, self.last_data] 

     else: 
      return [False, get_data[1]] 

    def call_all(self, get_id): 

     if get_id.strip() == "": 
      return "Please Insert Your Steam ID" 

     else: 

      self.url = 'http://steamcommunity.com/id/{0}/games/?tab=all'.format(get_id) 

      get_state_1 = self.send_request() 

      if get_state_1[0] is True: 

       get_state_2 = self.pars_data(get_state_1[1]) 
       return get_state_2[1] 

      else: 
       return get_state_1[1] 



# Call This Class Now: 

your_id = 'erfan1' 

make_object = SteamGameGrabber() 
get_result = make_object.call_all(your_id) 

if isinstance(get_result, dict): 

    print("Dict Format : ", get_result, "\n") 
    print("Target ID : ", my_id, "\n") 

    for names, appid in get_result.items(): 
     print(names, appid) 

else: 
    print(get_result) 

행운을 빌어 요 ...

0

나는이 개발자 웹 사이트를 찾았습니다.이 파일을 python 구현에 사용할 수 있습니까?

https://developer.valvesoftware.com/wiki/SteamID

한증 커뮤니티 ID

스팀 ID로

스팀 ID는 스팀 커뮤니티 웹 사이트에서 사용하기 위해 커뮤니티 ID를 증기로 변환 할 수 있습니다. X, Y 및 Z 상수를 SteamID : STEAM_X:Y:Z으로 정의합니다.

공식 W=Z*2+Y를 사용하여 32 비트 시스템

를 들어

가하는 SteamID 다음 링크로 변환 할 수 있습니다 : 는 http 또는 https://steamcommunity.com/path/[letter:1:W] 이 계정 유형의 문자가 발견 될 수 변환의 2 가지 방법이 있습니다 위 표에서 경로는 슬래시 기호 다음의 동일한 위치에서 찾을 수 있습니다. 예 : http://steamcommunity.com/gid/[g:1:4] 64 비트 시스템

:

하자 V 계정 SteamID64 타입 식별자 (16 진수 위 표에서 찾아 볼 수있다). 수식 W=Z*2+V+Y을 사용하면 SteamID를 다음 링크로 변환 할 수 있습니다. http 또는 https://steamcommunity.com/path/W 32 비트 방법의 경우 위의 표에서 슬래시 다음에 경로를 찾을 수 있습니다. 예 : http://steamcommunity.com/profiles/76561197960287930