Advertisement
Guest User

Untitled

a guest
May 25th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. import urllib.request, json, requests, time
  2. from discord_hooks import Webhook
  3. import math
  4.  
  5.  
  6. def killcheck():
  7. ship_ids = [3756, 11567, 3764, 671, 23773, 42126, 42241, 45649, 23919, 23917, 23913, 22852, 3514, 42125, 33675,
  8. 33395, 45531, 32790, 42245, 33673, 35779, 35781, 3518, 32209, 2836, 11942, 11940, 11011, 45530, 33397,
  9. 42246, 44996, 11936, 11938, 13202, 26840, 26842, 32788, 32207, 3516, 2834]
  10.  
  11. # pass true or false to the fuction so it can be used to start the region check
  12.  
  13. if killdata.get("package").get("killmail").get("attackers")[i].get("ship_type_id") in ship_ids:
  14. print("True")
  15. return True
  16.  
  17. else:
  18. print("False")
  19. return False
  20.  
  21.  
  22. ESI_URL = "https://esi.tech.ccp.is/latest"
  23.  
  24.  
  25. def regioncheck(system_id):
  26. home_regions = [10000005, 10000006, 10000007, 10000008, 10000009, 10000011, 10000018, 10000021, 10000027, 10000028]
  27.  
  28. def getconstellationid(system_id):
  29.  
  30. systems_url = '{}/universe/systems/{}/'.format(ESI_URL, system_id)
  31. with urllib.request.urlopen(systems_url) as url:
  32. solar_info = json.loads(url.read().decode())
  33.  
  34. constellation_id = solar_info["constellation_id"]
  35.  
  36. return constellation_id
  37.  
  38. pass
  39.  
  40. def getregionid(constellation_id):
  41.  
  42. constellation_url = '{}/universe/constellations/{}/'.format(ESI_URL, constellation_id)
  43. with urllib.request.urlopen(constellation_url) as url:
  44. constellation_info = json.loads(url.read().decode())
  45. region_id = constellation_info["region_id"]
  46. return region_id
  47.  
  48. pass
  49.  
  50. # runs the subfuctions to get the region id, then we check it against our home regions array and either end the fuction or push it to discord
  51.  
  52. constellation_id = getconstellationid(system_id)
  53. region_id = getregionid(constellation_id)
  54.  
  55. if region_id in home_regions:
  56. systems_url = '{}/universe/systems/{}/'.format(ESI_URL, target_sys_id)
  57. target_url = urllib.request.urlopen(systems_url)
  58. target_solar_info = json.loads(target_url.read().decode())
  59.  
  60. xtar = target_solar_info["position"]["x"]
  61. ytar = target_solar_info["position"]["y"]
  62. ztar = target_solar_info["position"]["z"]
  63.  
  64. distancem = math.sqrt(((xhome - xtar) ** 2) + ((yhome - ytar) ** 2) + ((zhome - ztar) ** 2)) #lightyear
  65. distancely = distancem / 9460730472580.04 / 1000 #lightyear
  66. discordpush(distancely)
  67. return True
  68.  
  69. else:
  70. print("not in home_regions")
  71.  
  72. pass
  73.  
  74.  
  75. def discordpush(distancely):
  76. url = 'https://discordapp.com/api/webhooks/449616342056828939/Yhv9q-59eHiWN8rCs8WnV9EkD61nS6dUVEIzDVZcz0-subj6plZ_I0nRHkdeJDci1vLo'
  77.  
  78. msg = Webhook(url,
  79. msg="HVT spotted, checkout this killmail! https://zkillboard.com/kill/{}/ \U0001f62e".format(killid))
  80.  
  81. msg1 = Webhook(url,
  82. msg="HVT is {0:.1f} lightyears away".format(
  83. distancely, killid))
  84.  
  85. msg.post()
  86. msg1.post()
  87.  
  88. pass
  89.  
  90. # forever loops the program
  91.  
  92.  
  93. while True:
  94.  
  95. ESI_URL = "https://esi.tech.ccp.is/latest"
  96.  
  97. # Home ESI
  98. home_sys_id = 30000794 # currently a24l-v
  99. home_systems_url = '{}/universe/systems/{}/'.format(ESI_URL, home_sys_id)
  100. home_url = urllib.request.urlopen(home_systems_url)
  101. solar_info = json.loads(home_url.read().decode())
  102.  
  103. xhome = solar_info["position"]['x']
  104. yhome = solar_info["position"]['y']
  105. zhome = solar_info["position"]['z']
  106.  
  107. try:
  108.  
  109. with urllib.request.urlopen("https://redisq.zkillboard.com/listen.php?queueID=AtrolNalelmir&ttw=1") as url:
  110. killdata = json.loads(url.read().decode())
  111.  
  112. attacklen = len(killdata["package"]["killmail"]["attackers"])
  113. killid = killdata["package"]["killID"]
  114. system_id = killdata["package"]["killmail"]["solar_system_id"]
  115. target_sys_id = system_id #for lightyear calc ezmode
  116.  
  117. # starts the killcheck and loops for each attacker
  118. i = 0
  119. while i < attacklen:
  120.  
  121. # assigns boolean value to target based on killcheck function, so we know if we should check region ids or not
  122. target = killcheck()
  123. print(target)
  124. if target == True:
  125. print("checking Region IDs")
  126. #regioncheck(system_id)
  127. if regioncheck(system_id) == True:
  128. break
  129. print(i)
  130. i = i + 1
  131.  
  132.  
  133.  
  134.  
  135. # #RedisQ gives out a null package if no killmail has come in for 10 seconds
  136. except TypeError:
  137. print(killdata, "sleeping for 1 seconds")
  138. time.sleep(0.001)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement