Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import steam
- import os
- USERNAME = 'lolmyusername'
- PASSWORD = 'lolmypassword'
- wa = steam.WebAuth(USERNAME, PASSWORD)
- wa.login()
- def send_steam_request(itemname):
- s = '?currency=1&appid=730&country=US&market_hash_name=' + itemname.replace(' ', '%20').replace('|', '%7C').replace('(', '%28').replace(')', '%29')
- return requests.get('http://steamcommunity.com/market/pricehistory/' + s, cookies=wa.session.cookies)
- items = ['M4A4 | Bullet Rain (Minimal Wear)', ] # 'AWP | Dragon Lore (Field-Tested)'
- for item in items:
- resp = send_steam_request(item)
- raw = '//Format: [Date]|[Price]|[Amount Traded]\n'
- dates = 'Dates: \n'
- prices = 'Prices: \n'
- amts = 'Amount Traded: \n'
- curamt = 0
- lastdate = ''
- for n in range(len(resp.json()['prices'])):
- v = resp.json()['prices'][n]
- d = 'zz'
- if n + 1 < len(resp.json()['prices']):
- d = resp.json()['prices'][n + 1][0][4:-12]
- if d not in lastdate:
- curamt += int(v[2])
- dates += v[0][:-7] + '\n'
- prices += str(v[1]) + '\n'
- amts += str(v[2]) + '\n'
- raw += v[0][:-7] + '|' + str(v[1]) + '|' + str(curamt) + '\n'
- curamt = 0
- else:
- curamt += int(v[2])
- lastdate = d
- path = os.getcwd().replace('\\', '/') + '/data/' + item.replace('|', '-')
- for d in os.listdir(os.getcwd()):
- if 'data' in d:
- break
- else:
- os.mkdir(os.getcwd().replace('\\', '/') + '/data')
- fr = open(path + '.dat', 'w')
- fr.write(raw)
- fr.close()
- print('Saved "' + path + '.dat' + '"')
- ff = open(path + '.txt', 'w')
- ff.write(dates + '\n' + prices + '\n' + amts)
- ff.close()
- print('Saved "' + path + '.txt' + '"')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement