Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.35 KB | None | 0 0
  1. import requests
  2. import json
  3. import time
  4. import threading
  5.  
  6.  
  7. class itemObj:
  8.  
  9. def __init__(self):
  10. self.name = ''
  11. self.type = ''
  12. self.quant = 0
  13. self.iconURL = ''
  14. self.unitPrice = 0
  15. self.worth = 0
  16. self.inventoryID = ''
  17.  
  18.  
  19. def update(itemList, POESESSID, ACCOUNTNAME, LEAGUE, TABCOUNT, displayVars, UPDATETIME, lock):
  20. while True:
  21. # with lock:
  22. #lock.acquire()
  23. print('Updating...')
  24. # url call for tab count
  25. urlTabs = 'https://www.pathofexile.com/character-window/get-stash-items?league=' + \
  26. LEAGUE+'&tabs=0&accountName=' + ACCOUNTNAME
  27. response = requests.post(
  28. urlTabs, headers={'Cookie': 'POESESSID='+POESESSID})
  29. if response.status_code == 200:
  30. tabData = response.json()
  31. TABCOUNT = tabData['numTabs']
  32. # for testing
  33. # TABCOUNT = 2
  34. # print(TABCOUNT)
  35. # url call for each tab, compiling data into itemList
  36. for tab in range(TABCOUNT):
  37. url = 'https://www.pathofexile.com/character-window/get-stash-items?league=' + \
  38. LEAGUE+'&tabs=0&tabIndex=' + \
  39. str(tab)+'&accountName=' + ACCOUNTNAME
  40. # print(url)
  41. response = requests.post(
  42. url, headers={'Cookie': 'POESESSID='+POESESSID})
  43. # print(response.status_code)
  44. if response.status_code == 200:
  45. data = response.json()
  46. items = data['items'] # strips off currency tab info
  47. # print(items)
  48.  
  49. for element in list(items):
  50. # print(element)
  51. newItem = itemObj()
  52. curName = element.get('name')
  53. if curName:
  54. newItem.name = curName
  55.  
  56. newItem.type = element.get('typeLine')
  57. newItem.iconURL = element.get('icon')
  58. newItem.inventoryID = element.get('inventoryId')
  59. curquant = element.get('stackSize')
  60. if curquant:
  61. newItem.quant = curquant
  62. else:
  63. newItem.quant = 1
  64. itemList.append(newItem)
  65.  
  66. # market data from compiled List
  67. # Div Cards
  68. url = 'https://poe.ninja/api/Data/GetDivinationCardsOverview?league='+LEAGUE
  69. response = requests.post(url)
  70. if response.status_code == 200:
  71. divData = response.json()
  72.  
  73. for dEl in list(divData['lines']):
  74. for iEl in list(itemList):
  75. if iEl.type == dEl['name']:
  76. iEl.unitPrice = dEl['chaosValue']
  77.  
  78. # Currency
  79. url = 'https://poe.ninja/api/Data/GetCurrencyOverview?league='+LEAGUE
  80. response = requests.post(url)
  81. if response.status_code == 200:
  82. cData = response.json()
  83.  
  84. for cEl in list(cData['lines']):
  85. for iEl in list(itemList):
  86. if iEl.type == cEl['currencyTypeName']:
  87. iEl.unitPrice = cEl['chaosEquivalent']
  88. elif iEl.type == 'Chaos Orb':
  89. iEl.unitPrice = iEl.quant
  90.  
  91. # Essences
  92. url = 'https://poe.ninja/api/Data/GetEssenceOverview?league='+LEAGUE
  93. response = requests.post(url)
  94. if response.status_code == 200:
  95. eData = response.json()
  96.  
  97. for eEl in list(eData['lines']):
  98. for iEl in list(itemList):
  99. if iEl.type == eEl['name']:
  100. iEl.unitPrice = eEl['chaosValue']
  101. # Fragments
  102. url = 'https://poe.ninja/api/Data/GetFragmentOverview?league='+LEAGUE
  103. response = requests.post(url)
  104. if response.status_code == 200:
  105. fData = response.json()
  106.  
  107. for fEl in list(fData['lines']):
  108. for iEl in list(itemList):
  109. if iEl.type == fEl['currencyTypeName']:
  110. iEl.unitPrice = fEl['chaosEquivalent']
  111.  
  112. # Prophecies
  113. url = 'https://poe.ninja/api/Data/GetProphecyOverview?league='+LEAGUE
  114. response = requests.post(url)
  115. if response.status_code == 200:
  116. pData = response.json()
  117.  
  118. for pEl in list(pData['lines']):
  119. for iEl in list(itemList):
  120. if iEl.type == pEl['name']:
  121. iEl.unitPrice = pEl['chaosValue']
  122. # Incubators
  123. # url = 'https://poe.ninja/api/Data/GetIncubatorOverview?league='+LEAGUE
  124. # response = requests.post(url)
  125. # if response.status_code == 200:
  126. # inData = response.json()
  127. #
  128. # for inEl in list(inData['lines']):
  129. # for iEl in list(itemList):
  130. # if iEl.type == inEl['name']:
  131. # iEl.unitPrice = inEl['chaosValue']
  132.  
  133. # Scarabs
  134. # url = 'https://poe.ninja/api/Data/GetScarabOverview?league='+LEAGUE
  135. # response = requests.post(url)
  136. # if response.status_code == 200:
  137. # sData = response.json()
  138. #
  139. # for sEl in list(sData['lines']):
  140. # for iEl in list(itemList):
  141. # if iEl.type == sEl['name']:
  142. # iEl.unitPrice = sEl['chaosValue']
  143.  
  144. # Maps
  145. url = 'https://poe.ninja/api/Data/GetMapOverview?league='+LEAGUE
  146. response = requests.post(url)
  147. if response.status_code == 200:
  148. mData = response.json()
  149.  
  150. for mEl in list(mData['lines']):
  151. for iEl in list(itemList):
  152. if iEl.name == '':
  153. if iEl.type == mEl['name']:
  154. iEl.unitPrice = mEl['chaosValue']
  155.  
  156. # Unique Armor
  157. url = 'https://poe.ninja/api/Data/GetUniqueArmourOverview?league='+LEAGUE
  158. response = requests.post(url)
  159. if response.status_code == 200:
  160. ufData = response.json()
  161.  
  162. for ufEl in list(ufData['lines']):
  163. for iEl in list(itemList):
  164. if iEl.name == ufEl['name']:
  165. iEl.unitPrice = ufEl['chaosValue']
  166. # Unique Weapon
  167. url = 'https://poe.ninja/api/Data/GetUniqueWeaponOverview?league='+LEAGUE
  168. response = requests.post(url)
  169. if response.status_code == 200:
  170. ufData = response.json()
  171.  
  172. for ufEl in list(ufData['lines']):
  173. for iEl in list(itemList):
  174. if iEl.name == ufEl['name']:
  175. iEl.unitPrice = ufEl['chaosValue']
  176. # Unique Flask
  177. url = 'https://poe.ninja/api/Data/GetUniqueFlaskOverview?league='+LEAGUE
  178. response = requests.post(url)
  179. if response.status_code == 200:
  180. ufData = response.json()
  181.  
  182. for ufEl in list(ufData['lines']):
  183. for iEl in list(itemList):
  184. if iEl.name == ufEl['name']:
  185. iEl.unitPrice = ufEl['chaosValue']
  186. # Unique Accessory
  187. url = 'https://poe.ninja/api/Data/GetUniqueAccessoryOverview?league='+LEAGUE
  188. response = requests.post(url)
  189. if response.status_code == 200:
  190. ujcData = response.json()
  191.  
  192. for ujcEl in list(ujcData['lines']):
  193. for iEl in list(itemList):
  194. if iEl.name == ujcEl['name']:
  195. iEl.unitPrice = ujcEl['chaosValue']
  196. # Unique Jewel
  197. url = 'https://poe.ninja/api/Data/GetUniqueJewelOverview?league='+LEAGUE
  198. response = requests.post(url)
  199. if response.status_code == 200:
  200. ujData = response.json()
  201.  
  202. for ujEl in list(ujData['lines']):
  203. for iEl in list(itemList):
  204. if iEl.name == ujEl['name']:
  205. iEl.unitPrice = ujEl['chaosValue']
  206. # Unique Map
  207. url = 'https://poe.ninja/api/Data/GetUniqueMapOverview?league='+LEAGUE
  208. response = requests.post(url)
  209. if response.status_code == 200:
  210. umData = response.json()
  211.  
  212. for umEl in list(umData['lines']):
  213. for iEl in list(itemList):
  214. if iEl.name == umEl['name']:
  215. iEl.unitPrice = umEl['chaosValue']
  216. #lock.release()
  217. print('Finished updating')
  218. output(itemList, displayVars, UPDATETIME)
  219.  
  220. time.sleep(30)
  221.  
  222.  
  223. def output(itemList, displayVars, UPDATETIME):
  224. # Overall output
  225. if displayVars[0] == 'All':
  226. for el in list(itemList):
  227. print(el.name, el.type, el.quant, el.iconURL,
  228. el.unitPrice, el.inventoryID, sep="___")
  229. else:
  230. for dVar in list(displayVars):
  231. for el in list(itemList):
  232. if el.inventoryID == dVar:
  233. print(el.name, el.type, el.quant, el.iconURL,
  234. el.unitPrice, el.inventoryID, sep="___")
  235.  
  236. UPDATETIME = time.strftime('%C')
  237. #print('Last updated: ' + UPDATETIME)
  238.  
  239.  
  240. def userInput(displayVars, itemList, UPDATETIME):
  241. while True:
  242. userin = input(
  243. 'Please enter stash tabs to display or EXIT(default All, format: "Stash1,Stash2...")--> ')
  244. displayVars = userin.split(',')
  245. if displayVars[0] == 'EXIT':
  246. endPgrm()
  247. output(itemList, displayVars, UPDATETIME)
  248.  
  249.  
  250. def endPgrm():
  251. exit()
  252.  
  253.  
  254. class inputThread(threading.Thread):
  255.  
  256. def __init__(self, t, *args):
  257. threading.Thread.__init__(self, target=t, args=args)
  258. self.daemon = True
  259. self.start()
  260.  
  261.  
  262. class updateThread(threading.Thread):
  263. def __init__(self, t, *args):
  264. threading.Thread.__init__(self, target=t, args=args)
  265. self.daemon = True
  266. self.start()
  267.  
  268. lock = threading.Lock()
  269.  
  270.  
  271. def main():
  272. # container of usable set items based off data
  273. itemList = []
  274. displayVars = ['All']
  275.  
  276. POESESSID = "4c836125ea7ecaa0f843af5a5edf8107"
  277. ACCOUNTNAME = 'CzyPudu'
  278. LEAGUE = 'Legion'
  279. TABCOUNT = 0 # gets overwritten on first call
  280. UPDATETIME = ''
  281.  
  282. inputThread(userInput(displayVars, itemList, UPDATETIME))
  283. updateThread(update(itemList, POESESSID, ACCOUNTNAME, LEAGUE, TABCOUNT, displayVars, UPDATETIME, lock))
  284.  
  285.  
  286.  
  287. if __name__ == '__main__':
  288. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement