Skip to content

Instantly share code, notes, and snippets.

@pazairfog
Last active June 1, 2017 13:23
Show Gist options
  • Select an option

  • Save pazairfog/a247909cac91b954b67c1823f354853b to your computer and use it in GitHub Desktop.

Select an option

Save pazairfog/a247909cac91b954b67c1823f354853b to your computer and use it in GitHub Desktop.
python POE parsing stash account
#! /usr/bin/python
import getopt, json, requests, sys, time, urllib2
# Nombre par defaut d'iteration pour recuperer les stashes.
loop = 5
try:
# Le premier argument est toujours le nom du script, on le retire.
opts, args = getopt.getopt(sys.argv[1:], "hl:", ["loop="])
except getopt.GetoptError:
print 'import.py -l <loop>'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'import.py -l <loop>'
sys.exit()
elif opt in ("-l", "--loop") and arg.isdigit():
loop = int(arg)
api = 'http://api.pathofexile.com/public-stash-tabs/'
for i in range(0, loop):
url = api
if 'next_id' in locals():
# On temporise pour ne pas surcharger l'API de POE.
time.sleep(1)
url += '?id=' + next_id
try:
object = urllib2.urlopen(url)
except urllib2.HTTPError, e:
print ('HTTPError = ' + str(e.code))
sys.exit(2)
except urllib2.URLError, e:
print ('URLError = ' + str(e.reason))
sys.exit(2)
except httplib.HTTPException, e:
print 'HTTPException'
sys.exit(2)
if 'object' in locals():
data = json.load(object)
next_id = str(data['next_change_id'])
for stashe in data['stashes']:
requests.post('http://ES:9200/poe/poe/' + stashe['id'], data=json.dumps(stashe))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment