Advertisement
Dimka_lang2

Untitled

Nov 26th, 2020
2,449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.22 KB | None | 0 0
  1. import json
  2. from time import sleep
  3. import steampy
  4. from steampy.client import Asset
  5. from steampy.utils import GameOptions
  6. from steampy.client import SteamClient
  7. import os
  8. import datetime
  9. import requests
  10. from colorama import Fore, init
  11.  
  12. init(autoreset=True)
  13.  
  14.  
  15. def time():
  16.     now = datetime.datetime.now()
  17.     return f'[{now.strftime("%d-%m-%Y %H:%M:%S")}]'
  18.  
  19.  
  20. def ChangeFile(fileName, Data):
  21.     with open(str(fileName), 'w') as file:
  22.         json.dump(Data, file, indent=4)
  23.         file.close()
  24.  
  25.  
  26. def steam_login(data):
  27.     maFile = json.load(open(data))
  28.     apikey = maFile["steam_api"]
  29.     proxy123 = maFile["proxy"]
  30.     try:
  31.         print(f'\n{time()} Logging to steam account: {data.split(".")[0]}')
  32.         steam_client = SteamClient(apikey)
  33.         print(f'{time()} Использую прокси: {proxy123}')
  34.         steam_client._session.proxies = {'https': str(proxy123)}
  35.         steam_client.login(maFile['account_name'], maFile['account_password'], data)
  36.  
  37.         print(f'{time()} Successfully logged in!\n')
  38.         return steam_client
  39.  
  40.     except requests.exceptions.ConnectionError:
  41.         print(f'{time()}{Fore.RED} Bad proxy')
  42.         sleep(15)
  43.         steam_login(data)
  44.     except steampy.exceptions.InvalidCredentials as ERR:
  45.         sleep(3)
  46.         print(f'{time()}{Fore.RED} {ERR}')
  47.         steam_login(data)
  48.  
  49.  
  50. def confirm(tradeid, steam_client, requestId, tm_api):
  51.     try:
  52.         steam_client._confirm_transaction(tradeid)
  53.     except:
  54.         userdata = json.load(open('data.json'))
  55.         userdata.update({requestId: 'used'})
  56.         ChangeFile('data.json', userdata)
  57.  
  58.         if requests.get(f'https://market.csgo.com/api/ReportCreatedTrade/{requestId}/{tradeid}?key={tm_api}').json()[
  59.             'success']:
  60.             print(f'{time()} Подтвердили трейд и оповестили маркет!')
  61.  
  62.  
  63. def create_trade(steam_client, asset_list, trade_url, msg):
  64.     if steam_client.is_session_alive():
  65.         trade_asset = []
  66.         for x in asset_list:
  67.             trade_asset.append(Asset(x, GameOptions.CS))
  68.         return steam_client.make_offer_with_url(trade_asset, [], trade_url, msg, True), steam_client
  69.     else:
  70.         steam_client = steam_login(f'{os.getcwd()}\\Settings\\Settings.json')
  71.         trade_asset = []
  72.         for x in asset_list:
  73.             trade_asset.append(Asset(x, GameOptions.CS))
  74.         return steam_client.make_offer_with_url(trade_asset, [], trade_url, msg, True), steam_client
  75.  
  76.  
  77. def data_check(requestId):
  78.     userdata = json.load(open('data.json'))
  79.     result = userdata.get(requestId)
  80.     return result
  81.  
  82.  
  83. def check_trades(tm_api):
  84.     ChangeFile('data.json', {})
  85.     steam_client = steam_login(f'{os.getcwd()}\\Settings\\Settings.json')
  86.     while tm_api:
  87.         try:
  88.             r = requests.get(f'https://market.csgo.com/api/ItemRequest/in/1/?key={tm_api}', timeout=5).json()
  89.             if r['success']:
  90.                 msg = r['request']['tradeoffermessage']
  91.                 url = r['request']['tradelink']
  92.                 requestId = r['requestId']
  93.                 asset_list = []
  94.                 for x in r['request']['items']:
  95.                     asset_list.append(x['assetid'])
  96.  
  97.                 if data_check(requestId) is None:
  98.                     d = create_trade(steam_client, asset_list, url, msg)
  99.                     steam_client = d[1]
  100.                     if d[0] is None:
  101.                         print(f'{time()} Не получилось создать трейд оффер')
  102.                     else:
  103.                         trade_id = d[0]['tradeofferid']
  104.                         confirm(trade_id, steam_client, requestId, tm_api)
  105.  
  106.             elif not r['success']:
  107.                 if r[
  108.                     'error'] == 'Ошибка создания заявки: Не удалось получить список предметов' or 'Error creating request: Failed to get list of items':
  109.                     ChangeFile('data.json', {})
  110.                 else:
  111.                     print(f'{time()}{Fore.RED} Ошибка при создании трейда: {r["error"]}')
  112.  
  113.             sleep(5)
  114.         except Exception as er:
  115.             print(f'{time()} Ошибка при check_trades: {er}{Fore.RESET}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement