Advertisement
Guest User

SteamBoat

a guest
May 3rd, 2017
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.79 KB | None | 0 0
  1. import requests
  2. import steam
  3. import os
  4.  
  5. USERNAME = 'lolmyusername'
  6. PASSWORD = 'lolmypassword'
  7.  
  8. wa = steam.WebAuth(USERNAME, PASSWORD)
  9. wa.login()
  10.  
  11.  
  12. def send_steam_request(itemname):
  13.     s = '?currency=1&appid=730&country=US&market_hash_name=' + itemname.replace(' ', '%20').replace('|', '%7C').replace('(', '%28').replace(')', '%29')
  14.     return requests.get('http://steamcommunity.com/market/pricehistory/' + s, cookies=wa.session.cookies)
  15.  
  16.  
  17. items = ['M4A4 | Bullet Rain (Minimal Wear)', ]  # 'AWP | Dragon Lore (Field-Tested)'
  18.  
  19. for item in items:
  20.     resp = send_steam_request(item)
  21.     raw = '//Format: [Date]|[Price]|[Amount Traded]\n'
  22.     dates = 'Dates: \n'
  23.     prices = 'Prices: \n'
  24.     amts = 'Amount Traded: \n'
  25.     curamt = 0
  26.     lastdate = ''
  27.     for n in range(len(resp.json()['prices'])):
  28.         v = resp.json()['prices'][n]
  29.         d = 'zz'
  30.         if n + 1 < len(resp.json()['prices']):
  31.             d = resp.json()['prices'][n + 1][0][4:-12]
  32.         if d not in lastdate:
  33.             curamt += int(v[2])
  34.             dates += v[0][:-7] + '\n'
  35.             prices += str(v[1]) + '\n'
  36.             amts += str(v[2]) + '\n'
  37.             raw += v[0][:-7] + '|' + str(v[1]) + '|' + str(curamt) + '\n'
  38.             curamt = 0
  39.         else:
  40.             curamt += int(v[2])
  41.         lastdate = d
  42.     path = os.getcwd().replace('\\', '/') + '/data/' + item.replace('|', '-')
  43.     for d in os.listdir(os.getcwd()):
  44.         if 'data' in d:
  45.             break
  46.     else:
  47.         os.mkdir(os.getcwd().replace('\\', '/') + '/data')
  48.     fr = open(path + '.dat', 'w')
  49.     fr.write(raw)
  50.     fr.close()
  51.     print('Saved "' + path + '.dat' + '"')
  52.     ff = open(path + '.txt', 'w')
  53.     ff.write(dates + '\n' + prices + '\n' + amts)
  54.     ff.close()
  55.     print('Saved "' + path + '.txt' + '"')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement