-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpull_items.py
More file actions
36 lines (30 loc) · 1.23 KB
/
pull_items.py
File metadata and controls
36 lines (30 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import requests
import json
import time
wowItemUrl='http://us.battle.net/api/wow/item/'
print str(int(time.time() * 1000))
errorsCount = 0
successCount = 0
countBase = 120945
for i in range(1, 20001):
itemid=countBase + i
lastRequestTime = time.time()
r = requests.get(wowItemUrl + str(itemid))
#{status: "nok",reason: "unable to get item information."}
#{status: "nok",reason: "When in doubt, blow it up. (page not found)"}
jsonResp = r.json()
if "status" in jsonResp and jsonResp["status"] == "nok":
#print "ERROR", jsonResp["reason"], "\n"
errorsCount += 1
if (errorsCount % 50) == 0:
print "Errors - "+str(errorsCount)+" Last id "+str(itemid)
else:
#print r.text, "\n"
requests.post("http://localhost:9200/wow/item/"+str(itemid), data=r.text)
successCount += 1
if (successCount % 50)==0:
print "fetched item "+str(itemid)
toWait = time.time() - (lastRequestTime+0.1)
if toWait>0:
time.sleep(toWait)
print "FINISH. Errors - "+str(errorsCount)+" Success - "+str(successCount)+" Last id "+str(itemid)