Created
April 22, 2015 07:13
-
-
Save saiberz/5aa7b05c36b7787199ed to your computer and use it in GitHub Desktop.
GG Dota Y
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
import requests | |
from requests import Session | |
import re | |
from pprint import pprint | |
import json | |
from time import sleep | |
url = 'http://steamcommunity.com/market/search/render/' | |
params = {'appid' : 570, 'start' : '1', 'count' : '1', 'sort_dir' : 'desc', 'sort_column' : 'quantity' } | |
urlb = 'http://steamcommunity.com/market/listings/570/' | |
params2 = {'start' : 1, 'count' : 1 , 'currency' : 1, 'language' : 'spanish'} | |
items = [] | |
for i in range(1,100): | |
while True: | |
item = {} | |
params['start'] = i | |
r1 = requests.get(url,params=params) | |
r1_json = json.loads(r1.text) | |
try: | |
r1_html = r1_json['results_html'] | |
price = re.findall(r'([0-9]*\.[0-9]{2})', r1_html) | |
ref = re.findall(r'href=\"(.*)\" id', r1_html) | |
name = re.findall(r'[0-9];">([A-z: \-\',0-9#]*)<\/span', r1_html) | |
r2 = requests.get(url2,params=params2) | |
r2_json = json.loads(r2.text) | |
r2_data = r2_json['assets']['570']['2'].itervalues().next() | |
item['url'] = ref[0] | |
item['price'] = price[0] | |
item['name'] = name[0] | |
item['sp_name'] = r2_data['market_name'] | |
item['type'] = temp['type'] | |
item['icon_url_large'] = 'http://steamcommunity-a.akamaihd.net/economy/image/' + temp['icon_url_large'] | |
items.append(item) | |
print i,r1.status_code,r2.status_code,name[0] | |
except: | |
sleep(5) | |
print "Error: " + str(i) | |
continue | |
break | |
with open('items.json', 'w') as outfile: | |
json.dump(items, outfile) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment