Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. from lxml import html # Used to parse XML
  2. import requests #used to service API request
  3.  
  4. itemtypeid1 = 34
  5. itemtypeid2 = 35
  6. regionid = 10000002
  7.  
  8. webpage = requests.get('http://api.eve-central.com/api/marketstat?typeid=%i&typeid=%i&regionlimit=%i' % (
  9. itemtypeid1, itemtypeid2, regionid))
  10.  
  11. if webpage.status_code == 200:
  12. data = html.fromstring(webpage.content)
  13. for item in data.iter('type'):
  14.  
  15.  
  16. buy_dict = {node.tag: node.text for node in item.xpath("buy/*")}
  17. sell_dict = {node.tag: node.text for node in item.xpath("sell/*")}
  18.  
  19. #Variables for output
  20. itemid = (item.get("id"))
  21. buymin = buy_dict['min']
  22. buymax = buy_dict['max']
  23. buymedian = buy_dict['median']
  24. buyvolume = buy_dict['volume']
  25. buyaverage = buy_dict['avg']
  26.  
  27. #Fail if api webpage unavaliable
  28. else:
  29. print "Webpage unavaliable"
  30. Webpage.raise_for_status()
  31.  
  32.  
  33. #############################################################################
  34.  
  35.  
  36. import psycopg2
  37.  
  38. connection = psycopg2.connect(database='evemarketdata', user='postgres', password='black3car')
  39.  
  40. #open a cursor to perform DB operations
  41. cursor = connection.cursor()
  42.  
  43. #create new table
  44. cursor.execute("CREATE TABLE arkonor (itemid integer primary key, min integer, max integer, median integer, volume integer, average integer);")
  45.  
  46. #Insert row data into DB table
  47. cursor.execute("""INSERT INTO arkonor (typeid, min, max, median, volume, average)
  48. VALUES (%s, %s, %s, %s, %s, %s, %s, %s)""",
  49. ('itemid', 'buymin', 'buymax', 'buymedian', 'buyvolume', 'buyaverage'))
  50.  
  51.  
  52. #Commits all changes does with cursor
  53. #connection.commit()
  54.  
  55. Traceback (most recent call last):
  56.  
  57. File "E:Eve SpreadsheetsPythonPostgreConnect.py", line 49, in <module>
  58.  
  59. ('itemid', 'buymin', 'buymax', 'buymedian', 'buyvolume', 'buyaverage'))
  60.  
  61. IndexError: tuple index out of range
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement