Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.15 KB | None | 0 0
  1. import websocket
  2. import threading
  3. import time
  4. import json
  5. import requests
  6. import os
  7. import sys
  8. header = [
  9. "Accept-Encoding: gzip, deflate, br",
  10. "Accept-Language: uk-UA,uk; q = 0.9,ru; q = 0.8,en - US; q = 0.7,en; q = 0.6",
  11. "Cache-Control: no-cache",
  12. "Connection: Upgrade",
  13. "Pragma: no-cache",
  14. "Upgrade: websocket",
  15. "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36",
  16. ]
  17.  
  18. ws = websocket.create_connection("wss://gamdomtr.com/socket.io/?EIO=3&transport=websocket",
  19.                                 origin="https://gamdomtr.com",
  20.                                 host="gamdomtr.com")
  21. print(ws.recv())
  22. ws.send("40/p2p,")
  23. def ping():
  24.     while True:
  25.         ws.send("2")
  26.         # print(ws.recv())
  27.         time.sleep(4)
  28.  
  29.  
  30. def shop():
  31.     while True:
  32.         items_list = []
  33.         items = ws.recv()
  34.         if items != "3":
  35.             try:
  36.                 items = json.loads(items[7::])
  37.                 if items[0] == 'initialize':
  38.                     for i in items[1]['listings']:
  39.                         if i['item_count'] == 1:
  40.                             name = i['items'][0]['market_name']
  41.                             price = i['total_price']
  42.                             item = {
  43.                                 'name': name,
  44.                                 'price': round(price/1000, 2)
  45.                             }
  46.                             items_list.append(item)
  47.                     with open('items.json', 'w') as data:
  48.                         json.dump(items_list, data)
  49.                 elif items[0] == "newListing":
  50.                     if items[1]['item_count'] == 1:
  51.                             name = items[1]['items'][0]['market_name']
  52.                             price = items[1]['total_price']
  53.                             item = {
  54.                                 'name': name,
  55.                                 'price': round(price/1000, 2)
  56.                             }
  57.                             print(item)
  58.                             with open('items.json', 'r') as data:
  59.                                 items_list = json.load(data)
  60.                             items_list.append(item)
  61.                             with open('items.json', 'w') as data:
  62.                                 json.dump(items_list, data)
  63.                 elif items[0] == "removeListing":
  64.                     if items[1]['item_count'] == 1:
  65.                         with open('items.json', 'r') as data:
  66.                             itemss = json.load(data)
  67.                         for i in itemss:
  68.                             if i['name'] == items[1]['items'][0]['market_name']:
  69.                                 itemss.remove(i)
  70.                         with open('items.json', 'w') as data:
  71.                             json.dump(itemss, data)
  72.             except json.decoder.JSONDecodeError:
  73.                 pass
  74.  
  75. def parse():
  76.     while True:
  77.         print('##############################')
  78.         try:
  79.             with open('items.json', 'r') as data:
  80.                 items = json.load(data)
  81.             for i in items:
  82.                 if 'profit' not in i:
  83.                     req = json.loads(requests.get('http://steamcommunity.com/market/'
  84.                                        'priceoverview/?appid=730'
  85.                                        '&currency=1&market_hash_name='+ i['name']).text)
  86.                     st = req['lowest_price'][1::]
  87.                     i['steam'] = st
  88.                     i['profit'] = round((1-(i['price'] / (float(i['steam']) * 0.87)))*100, 2)
  89.                     with open('items.json', 'w') as data:
  90.                         json.dump(items, data)
  91.                 print(i)
  92.             time.sleep(5)
  93.         except:
  94.             pass
  95.  
  96. def exit():
  97.     input()
  98.     os.remove('items.json')
  99.     sys.exit()
  100.  
  101. threading_ping = threading.Thread(target=ping)
  102. threading_shop = threading.Thread(target=shop)
  103. threading_parse = threading.Thread(target=parse)
  104. threading_exit = threading.Thread(target=exit)
  105.  
  106. threading_ping.start()
  107. threading_exit.start()
  108. threading_shop.start()
  109. threading_parse.start()
  110.  
  111. threading_ping.join()
  112. threading_exit.join()
  113. threading_shop.join()
  114. threading_parse.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement