Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.22 KB | None | 0 0
  1. import requests
  2. import json
  3. import math
  4. from datetime import datetime
  5. min_keys = 15
  6. max_keys = 150
  7. hat_list = ["Charmer's Chapeau","Le Party Phantom","Fancy Fedora","Aviator Assassin","Hat of Cards","L'homme Burglerre","D\u00e9tective Noir","Frenchman's Beret"]
  8. current_time = datetime.now()
  9. percentage = 5
  10. effect_qs_dict = {'6':'45', #Green Confetti
  11. '7':'45', #Purple Confetti
  12. '8':'40', #Haunted Ghosts
  13. '9':'35', #Green Energy
  14. '10':'35', #Purple Energy
  15. '11':'40', #Circling TF Logo
  16. '12':'45', #Massed Flies
  17. '13':'35', #Burning Flames
  18. '14':'35', #Scorching Flames
  19. '17':'35', #Sunbeams
  20. '29':'40', #Stormy Storm
  21. '33':'40', #Orbiting Fire
  22. '34':'45', #Bubbling
  23. '35':'45', #Smoking
  24. '36':'45', #Steaming
  25. '38':'35', #Cloudy Moon
  26. '56':'45', #Kill-a-Watt
  27. '57':'45', #Terror-Watt
  28. '58':'45', #Cloud 9
  29. '70':'35', #Time Warp
  30. '15':'40', #Searing Plasma
  31. '16':'40', #Vivid Plasma
  32. '18':'40', #Circling Peace Sign
  33. '19':'40', #Circling Heart
  34. '30':'40', #Blizzardy Storm
  35. '31':'45', #Nuts n' Bolts
  36. '32':'45', #Orbiting Planets
  37. '37':'45', #Flaming Lantern
  38. '39':'45', #Cauldron Bubbles
  39. '40':'45', #Eerie Orbiting Fire
  40. '43':'30', #Knifestorm
  41. '44':'30', #Misty Skull
  42. '45':'30', #Harvest Moon
  43. '46':'30', #It's A Secret To Everybody
  44. '47':'30', #Stormy 13th Hour
  45. '59':'45', #Aces High
  46. '60':'45', #Dead Presidents
  47. '61':'45', #Miami Nights
  48. '62':'40', #Disco Beat Down
  49. '63':'40', #Phosphorous
  50. '64':'40', #Sulphurous
  51. '65':'45', #Memory Leak
  52. '66':'45', #Overclocked
  53. '67':'45', #Electrostatic
  54. '68':'45', #Power Surge
  55. '69':'35', #Anti-Freeze
  56. '71':'35', #Green Black Hole
  57. '72':'35', #Roboactive
  58. '73':'30', #Arcana
  59. '74':'30', #Spellbound
  60. '75':'30', #Chiroptera Venenata
  61. '76':'30', #Poisoned Shadows
  62. '77':'30', #Something Burning This Way Comes
  63. '78':'30', #Hellfire
  64. '79':'30', #Darkblaze
  65. '80':'30', #Demonflame
  66. '3001':'69', #Showstopper
  67. '3003':'69', #Holy Grail
  68. '3004':'69', #'72
  69. '3005':'69', #Fountain of Delight
  70. '3006':'69', #Screaming Tiger
  71. '3007':'69', #Skill Gotten Gains
  72. '3008':'69', #Midnight Whirlwind
  73. '3009':'69', #Silver Cyclone
  74. '3010':'69', #Mega Strike
  75. '81':'30', #Bonzo The All-Gnawing
  76. '82':'40', #Amaranthine
  77. '83':'40', #Stare From Beyond
  78. '84':'40', #The Ooze
  79. '85':'30', #Ghastly Ghosts Jr
  80. '86':'30', #Haunted Phantasm Jr
  81. '3011':'69', #Haunted Phantasm
  82. '3012':'69', #Ghastly Ghosts
  83. '87':'35', #Frostbite
  84. '88':'45', #Molten Mallard
  85. '89':'40', #Morning Glory
  86. '90':'40', #Death at Dusk
  87. '91':'69', #Abduction
  88. '92':'69', #Atomic
  89. '93':'69', #Subatomic
  90. '94':'69', #Electric Hat Protector
  91. '95':'69', #Magnetic Hat Protector
  92. '96':'69', #Voltaic Hat Protector
  93. '97':'69', #Galactic Codex
  94. '98':'69', #Ancient Codex
  95. '99':'35', #Nebula
  96. '100':'69', #Death by Disco
  97. '101':'69', #It's a mystery to everyone
  98. '102':'69', #It's a puzzle to me
  99. '103':'69', #Ether Trail
  100. '104':'69', #Nether Trail
  101. '105':'69', #Ancient Eldritch
  102. '106':'69', #Eldritch Flame
  103. '701':'69', #Weapon Effect
  104. '702':'69', #Weapon Effect
  105. '703':'69', #Weapon Effect
  106. '704':'69', #Weapon Effect
  107. '107':'69', #Neutron Star
  108. '108':'69', #Tesla Coil
  109. '109':'69', #Startstorm Slumber
  110. '110':'69', #Starstorm Insomnia
  111. '3014':'69', #Spectral Swirl
  112. '3015':'69', #Infernal Flame
  113. '3013':'69', #Hellish Inferno
  114. '3016':'69'} #Infernal Smoke
  115.  
  116. price_order_list = ["Burning Flames","Scorching Flames","Sunbeams","Bonzo The All-Gnawing","Spellbound","Arcana","Poisoned Shadows","Chiroptera Venenata","Something Burning This Way Comes","Darkblaze","Hellfire","Demonflame","Knifestorm","Stormy 13th Hour","Harvest Moon","It's A Secret To Everybody","Misty Skull","Cloudy Moon","Ghastly Ghosts Jr","Haunted Phantasm Jr","Roboactive","Anti-Freeze","Purple Energy","Green Energy","Green Black Hole","Time Warp","Frostbite","Sulphurous","Amaranthine","The Ooze","Stare From Beyond","Phosphorous","Morning Glory","Death at Dusk","Disco Beat Down","Circling Heart","Vivid Plasma","Haunted Ghosts","Searing Plasma","Miami Nights","Cloud 9","Stormy Storm","Blizzardy Storm","Circling Peace Sign","Circling TF Logo","Orbiting Fire","Molten Mallard","Eerie Orbiting Fire","Flaming Lantern","Terror-Watt","Kill-a-Watt","Purple Confetti","Green Confetti","Cauldron Bubbles","Smoking","Steaming","Bubbling","Power Surge","Electrostatic","Memory Leak","Overclocked","Aces High","Dead Presidents","Orbiting Planets","Nuts n' Bolts","Massed Flies"]
  117.  
  118. effect_dict={'6':'Green Confetti','7':'Purple Confetti','8':'Haunted Ghosts','9':'Green Energy','10':'Purple Energy','11':'Circling TF Logo','12':'Massed Flies','13':'Burning Flames','14':'Scorching Flames','17':'Sunbeams','29':'Stormy Storm','33':'Orbiting Fire','34':'Bubbling','35':'Smoking','36':'Steaming','38':'Cloudy Moon','56':'Kill-a-Watt','57':'Terror-Watt','58':'Cloud 9','70':'Time Warp','15':'Searing Plasma','16':'Vivid Plasma','18':'Circling Peace Sign','19':'Circling Heart','30':'Blizzardy Storm','31':"Nuts n' Bolts",'32':'Orbiting Planets','37':'Flaming Lantern','39':'Cauldron Bubbles','40':'Eerie Orbiting Fire','43':'Knifestorm','44':'Misty Skull','45':'Harvest Moon','46':"It's A Secret To Everybody",'47':'Stormy 13th Hour','59':'Aces High','60':'Dead Presidents','61':'Miami Nights','62':'Disco Beat Down','63':'Phosphorous','64':'Sulphurous','65':'Memory Leak','66':'Overclocked','67':'Electrostatic','68':'Power Surge','69':'Anti-Freeze','71':'Green Black Hole','72':'Roboactive','73':'Arcana','74':'Spellbound','75':"Chiroptera Venenata",'76':'Poisoned Shadows','77':'Something Burning This Way Comes','78':'Hellfire','79':'Darkblaze','80':'Demonflame','3001':'Showstopper','3003':'Holy Grail','3004':'72','3005':'Fountain of Delight','3006':'Screaming Tiger','3007':'Skill Gotten Gains','3008':'Midnight Whirlwind','3009':'Silver Cyclone','3010':'Mega Strike','81':'Bonzo The All-Gnawing','82':'Amaranthine','83':'Stare From Beyond','84':'The Ooze','85':'Ghastly Ghosts Jr','86':'Haunted Phantasm Jr','3011':'Haunted Phantasm','3012':'Ghastly Ghosts','87':'Frostbite','88':'Molten Mallard','89':'Morning Glory','90':'Death at Dusk','91':'Abduction','92':'Atomic','93':'Subatomic','94':'Electric Hat Protector','95':'Magnetic Hat Protector','96':'Voltaic Hat Protector','97':'Galactic Codex','98':'Ancient Codex','99':'Nebula','100':'Death by Disco','101':'Its a mystery to everyone','102':'Its a puzzle to me','103':'Ether Trail','104':'Nether Trail','105':'Ancient Eldritch','106':'Eldritch Flame','701':'Weapon Effect','702':'Weapon Effect','703':'Weapon Effect','704':'Weapon Effect','107':'Neutron Star','108':'Tesla Coil','109':'Startstorm Slumber','110':'Starstorm Insomnia','3014':'Spectral Swirl','3015':'Infernal Flame','3013':'Hellish Inferno','3016':'Infernal Smoke'}
  119.  
  120. with open('api_key.txt', 'r') as myfile:
  121. backpack_api_token = myfile.read().replace('\n', '')
  122.  
  123. print('Requesting backpack.tf for prices')
  124. payload = {'key':backpack_api_token}
  125. r1 = requests.get('http://backpack.tf/api/IGetPrices/v4',params=payload)
  126. ret1 = r1.json()
  127. print('Response Recieved')
  128.  
  129. if ret1['response']['success'] == 0:
  130. print('300 second cooldown in effect, loading old json file')
  131. with open('response.json') as json_data:
  132. ret1 = json.load(json_data)
  133. else:
  134. with open('response.json', 'w') as outfile:
  135. json.dump(ret1, outfile)
  136.  
  137. open('output.txt', 'w').close()
  138.  
  139. with open("output.txt", "a", encoding='utf-8') as myfile:
  140. myfile.write('[b][color=yellow]HI, IM QUICKBUYING THESE UNUSUALS![/color]\n\n')
  141. myfile.write('[color=#00FF04]CURRENTLY IN STOCK:[/color] [color=yellow]0[/color] [color=#00FF04]keys and[/color] [color=yellow]0[/color] [color=#00FF04]ref![/color]\n\n')
  142. myfile.write('[color=yellow]Im quickbuying almost[/color] [color=crimson]ANY[/color] [color=yellow]hat as long as its[/color] [color=crimson]30[/color][color=yellow]/[/color][color=crimson]35%[/color] [color=yellow]off High Tier,[/color] [color=crimson]40%[/color] [color=yellow]off Mid Tier and[/color] [color=crimson]45%[/color] [color=yellow]off Low Tier effects and meets[/color] [color=crimson]ALL[/color] [color=yellow]of my rules![/color]\n')
  143. myfile.write('[color=crimson]Im[/color] [color=yellow]MOSTLY[/color] [color=crimson]interested in[/color] [color=yellow]100[/color] [color=crimson](and less) key unusuals![/color]\n')
  144. myfile.write('[color=yellow]Press[/color] [color=crimson]F3[/color] [color=yellow]to search for the unusual you are quickselling![/color]\n')
  145. myfile.write('[color=crimson]My key stock is limited, so I get to choose the hats I buy![/color]\n')
  146. myfile.write('[color=yellow]Any unusuals that exceed my key stock cannot be purchased![/color]\n')
  147. myfile.write('[color=crimson]I always keep my key stock updated![/color]\n')
  148. myfile.write('[color=yellow]I pretty much always keep the prices listed below in date![/color]\n')
  149. myfile.write('[color=crimson]I have one of the[/color] [color=yellow]BEST[/color] [color=crimson]prices on the market![/color]\n\n')
  150. myfile.write('[color=yellow]🔥[/color] [color=crimson]30[/color][color=yellow]/[/color][color=crimson]35%[/color] [color=yellow]off High Tier effects![/color]\n')
  151. myfile.write('[color=yellow]🔥[/color] [color=crimson]40%[/color] [color=yellow]off Mid Tier effects![/color]\n')
  152. myfile.write('[color=yellow]🔥[/color] [color=crimson]45%[/color] [color=yellow]off Low Tier effects![/color]\n\n')
  153. myfile.write('[color=red]RULES:[/color]\n\n')
  154. myfile.write('[color=crimson]🔥[/color] [color=yellow]I do[/color] [color=crimson]NOT[/color] [color=yellow]buy Robo hats, Taunts and hats with 2016 Halloween effects![/color]\n')
  155. myfile.write('[color=crimson]🔥[/color] [color=yellow]If your unusual is[/color] [color=crimson]DUPED[/color][color=yellow], I will pay additional[/color] [color=crimson]10%[/color] [color=yellow]less![/color]\n[color=crimson]🔥[/color] [color=yellow]If your unusual costs over[/color] [color=crimson]100[/color] [color=yellow]keys, I will pay additional[/color] [color=crimson]5%[/color] [color=yellow]less![/color]\n')
  156. myfile.write('[color=crimson]🔥[/color] [color=yellow]If your unusual costs over[/color] [color=crimson]150[/color] [color=yellow]keys, I will[/color] [color=crimson]NOT[/color] [color=yellow]buy it![/color]\n')
  157. myfile.write('[color=crimson]🔥[/color] [color=yellow]If your hat is overpriced[/color][color=crimson]/[/color][color=yellow]inflated[/color][color=crimson]/[/color][color=yellow]outdated, i will[/color] [color=crimson]NOT[/color] [color=yellow]value it at current bp.tf price (i will most likely value it lower)![/color]\n\n')
  158. myfile.write('[color=yellow]Send me a trade offer here:[/color][/b] https://steamcommunity.com/tradeoffer/new/?partner=134757237&token=A-Bi9UpQ\n')
  159. myfile.write('[color=crimson]-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------[/color]\n')
  160.  
  161.  
  162.  
  163. for name,prices in ret1['response']['items'].items():
  164. for qualtiy,values in prices['prices'].items():
  165. if qualtiy == '5':
  166.  
  167. check_list = price_order_list
  168. price_check_dict = {}
  169. for check_effect in check_list:
  170. for chk_name,chk_prices in ret1['response']['items'].items():
  171. for chk_qualtiy,chk_values in chk_prices['prices'].items():
  172. if chk_qualtiy == '5' and 'Craftable' in chk_values['Tradable'].keys() and chk_name == name:
  173. if isinstance(chk_values['Tradable']['Craftable'],dict):
  174. for chk_effect,chk_price in chk_values['Tradable']['Craftable'].items():
  175. if chk_name in hat_list and chk_effect in effect_qs_dict.keys():
  176. if chk_price['currency'] == 'keys':
  177. chk_low = chk_price['value']
  178. if 'value_high' in chk_price.keys():
  179. chk_high = chk_price['value_high']
  180. else:
  181. chk_high = chk_low
  182. chk_avg_price = (chk_high + chk_low) / 2
  183. chk_last_updated = datetime.fromtimestamp(chk_price['last_update'])
  184. chk_delta = current_time - chk_last_updated
  185. #print(chk_name+name+effect_dict[chk_effect]+check_effect)
  186. if chk_name == name and effect_dict[chk_effect] == check_effect:
  187. price_check_dict[effect_dict[chk_effect]] = (chk_avg_price,chk_delta.days)
  188. indate_list = []
  189. for effect_name in price_order_list:
  190. if effect_name in price_check_dict.keys():
  191. if price_check_dict[effect_name][1] < 90:
  192. indate_list.append([effect_name,price_check_dict[effect_name][0],price_check_dict[effect_name][1]])
  193. #print(name)
  194.  
  195. remove_list = []
  196. for i in range(len(indate_list)):
  197. for j in range(i):
  198. #print(i,j)
  199. if indate_list[i][1] > indate_list[j][1]:
  200. remove_list.append(indate_list[i])
  201. break
  202. for item in remove_list:
  203. indate_list.remove(item)
  204. if indate_list:
  205. max_predicted_value = indate_list[0][1]
  206. else:
  207. max_predicted_value = 0
  208. for i in range(len(indate_list) - 1):
  209. distance = price_order_list.index(indate_list[i+1][0]) - price_order_list.index(indate_list[0][0])
  210. predicted_value = indate_list[i+1][1] * ((1+percentage/100)**distance)
  211. if predicted_value < max_predicted_value:
  212. max_predicted_value = (max_predicted_value + predicted_value) / 2
  213.  
  214.  
  215. if name in hat_list:
  216. with open("output.txt", "a", encoding='utf-8') as myfile:
  217. myfile.write('\n[b][color=#00FF04]'+name+'[/color][/b]\n\n')
  218.  
  219. if 'Craftable' in values['Tradable'].keys():
  220. if isinstance(values['Tradable']['Craftable'],dict):
  221.  
  222. with open("output.txt", "a", encoding='utf-8') as myfile:
  223. myfile.write('[color=red]High Tier:[/color]\n\n')
  224.  
  225. for effect,price in values['Tradable']['Craftable'].items():
  226. if price['currency'] == 'keys' and effect_qs_dict[str(effect)] == '35':
  227. low = price['value']
  228. if 'value_high' in price.keys():
  229. high = price['value_high']
  230. else:
  231. high = low
  232. avg_price = (high + low) / 2
  233. last_updated = datetime.fromtimestamp(price['last_update'])
  234. delta = current_time - last_updated
  235.  
  236. if indate_list:
  237. distance = price_order_list.index(indate_list[0][0]) - price_order_list.index(effect_dict[effect])
  238. if distance < 0:
  239. predicted_price = max_predicted_value * ((1-(percentage/100))**abs(distance))
  240. else:
  241. predicted_price = max_predicted_value * ((1+(percentage/100))**abs(distance))
  242. #print(name,effect_dict[effect],'Bp.tf price - ' + str(avg_price),'Predicted price - '+str(predicted_price),distance)
  243. if predicted_price < avg_price:
  244. avg_price = predicted_price
  245. #print(name,effect_dict[effect],avg_price, distance)
  246. if avg_price > min_keys and avg_price < max_keys:
  247. if avg_price > 100:
  248. qs_price = int(avg_price * (100 - int(effect_qs_dict[effect] )- 5) / 100)
  249. else:
  250. qs_price = int(avg_price * (100 - int(effect_qs_dict[effect])) / 100)
  251. if qs_price < 7:
  252. qs_price = 7
  253. if qs_price < 150:
  254. with open("output.txt", "a", encoding='utf-8') as myfile:
  255. myfile.write(effect_dict[str(effect)]+' - '+str(qs_price)+' keys'+'\n')
  256.  
  257. with open("output.txt", "a", encoding='utf-8') as myfile:
  258. myfile.write('\n[color=crimson]-------------------------------------------------------------------------------[/color]\n\n[color=orange]Mid Tier:[/color]\n\n')
  259.  
  260. for effect,price in values['Tradable']['Craftable'].items():
  261. if price['currency'] == 'keys' and effect_qs_dict[str(effect)] == '40':
  262. low = price['value']
  263. if 'value_high' in price.keys():
  264. high = price['value_high']
  265. else:
  266. high = low
  267. avg_price = (high + low) / 2
  268. last_updated = datetime.fromtimestamp(price['last_update'])
  269. delta = current_time - last_updated
  270.  
  271. if indate_list:
  272. distance = price_order_list.index(indate_list[0][0]) - price_order_list.index(effect_dict[effect])
  273. if distance < 0:
  274. predicted_price = max_predicted_value * ((1-(percentage/100))**abs(distance))
  275. else:
  276. predicted_price = max_predicted_value * ((1+(percentage/100))**abs(distance))
  277.  
  278. if predicted_price < avg_price:
  279. avg_price = predicted_price
  280. #print(name,effect_dict[effect],avg_price, distance)
  281. if avg_price > min_keys and avg_price < max_keys:
  282. if avg_price > 100:
  283. qs_price = int(avg_price * (100 - int(effect_qs_dict[effect] )- 5) / 100)
  284. else:
  285. qs_price = int(avg_price * (100 - int(effect_qs_dict[effect])) / 100)
  286. if qs_price < 7:
  287. qs_price = 7
  288. if qs_price < 150:
  289. with open("output.txt", "a", encoding='utf-8') as myfile:
  290. myfile.write(effect_dict[str(effect)]+' - '+str(qs_price)+' keys'+'\n')
  291.  
  292. with open("output.txt", "a", encoding='utf-8') as myfile:
  293. myfile.write('\n[color=crimson]-------------------------------------------------------------------------------[/color]\n\n[color=orange]Low Tier:[/color]\n\n')
  294.  
  295. for effect,price in values['Tradable']['Craftable'].items():
  296. if price['currency'] == 'keys' and effect_qs_dict[str(effect)] == '45':
  297. low = price['value']
  298. if 'value_high' in price.keys():
  299. high = price['value_high']
  300. else:
  301. high = low
  302. avg_price = (high + low) / 2
  303. last_updated = datetime.fromtimestamp(price['last_update'])
  304. delta = current_time - last_updated
  305.  
  306. if indate_list:
  307. distance = price_order_list.index(indate_list[0][0]) - price_order_list.index(effect_dict[effect])
  308. if distance < 0:
  309. predicted_price = max_predicted_value * ((1-(percentage/100))**abs(distance))
  310. else:
  311. predicted_price = max_predicted_value * ((1+(percentage/100))**abs(distance))
  312.  
  313. if predicted_price < avg_price:
  314. avg_price = predicted_price
  315. #print(name,effect_dict[effect],avg_price, distance)+
  316. if avg_price > min_keys and avg_price < max_keys:
  317. if avg_price > 100:
  318. qs_price = int(avg_price * (100 - int(effect_qs_dict[effect] )- 5) / 100)
  319. else:
  320. qs_price = int(avg_price * (100 - int(effect_qs_dict[effect])) / 100)
  321. if qs_price < 7:
  322. qs_price = 7
  323. if qs_price < 150:
  324. with open("output.txt", "a", encoding='utf-8') as myfile:
  325. myfile.write(effect_dict[str(effect)]+' - '+str(qs_price)+' keys'+'\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement