Initial version.
authorCMDR furrycat <elite@furrycat.net>
Sun, 5 Nov 2017 18:38:55 +0000 (18:38 +0000)
committerCMDR furrycat <elite@furrycat.net>
Sun, 5 Nov 2017 18:38:55 +0000 (18:38 +0000)
README.md [new file with mode: 0644]
load.py [new file with mode: 0644]

diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..f8b7e93
--- /dev/null
+++ b/README.md
@@ -0,0 +1,10 @@
+This is a simple plugin for explorers who wish to contribute scan data to EDSM.
+
+When jumping to a new system the plugin will check if EDSM has information on
+the arrival star of the destination system.  If not it will display a message
+prompting you to scan the star and submit data.
+
+Knowing the arrival star is crucial for route plotting tools which check for
+scoopable stars and jet cone boosts.  For systems which are initially
+discovered for all players, the lack of arrival star data is indicative of a
+system that has not had its navigation beacon scanned.
diff --git a/load.py b/load.py
new file mode 100644 (file)
index 0000000..f119002
--- /dev/null
+++ b/load.py
@@ -0,0 +1,89 @@
+import requests
+import sys
+import threading
+import urllib2
+
+import Tkinter as tk
+from ttkHyperlinkLabel import HyperlinkLabel
+
+from config import config
+
+this = sys.modules[__name__]
+this.frame = None
+this.edsm_session = None
+this.edsm_data = None
+
+def plugin_start():
+  return 'MissingArrivalStar'
+
+def plugin_app(parent):
+  this.frame = tk.Frame(parent)
+  this.frame.columnconfigure(2, weight=1)
+  this.frame.bind('<<MissingArrivalStar>>', edsm_callback)
+  this.widget_label = tk.Label(this.frame, text = 'Arrival star:')
+  this.widget_label.grid(row = 0, column = 0, sticky = tk.W)
+  this.widget = tk.Label(this.frame, text = '')
+  this.widget.grid(row = 0, column = 1, sticky = tk.W)
+  return this.frame
+
+def highlight(b):
+  if b:
+    this.widget['fg'] = config.get('dark_highlight')
+  else:
+    this.widget['fg'] = config.get('dark_text')
+
+def arrival_star_checking():
+  highlight(False)
+  this.widget['text'] = 'Checking EDSM'
+
+def arrival_star_known(star_class):
+  highlight(False)
+  this.widget['text'] = star_class
+
+def arrival_star_unknown():
+  highlight(True)
+  this.widget['text'] = 'UNKNOWN!  Please scan.'
+
+def arrival_star_error():
+  highlight(True)
+  this.widget['text'] = 'ERROR!'
+  plug.show_error('Failed to query EDSM for arrival star')
+
+def journal_entry(cmdr, is_beta, system, station, entry, state):
+  if entry['event'] == 'Scan':
+    if not float(entry['DistanceFromArrivalLS']):
+      arrival_star_known('SCANNED')
+  elif entry['event'] == 'StartJump':
+    arrival_star_known('Witchspace')
+  elif entry['event'] in ['Location', 'FSDJump']:
+    query_arrival_star(entry['StarSystem'])
+
+def cmdr_data(data, is_beta):
+  return query_arrival_star(data['lastSystem']['name'])
+
+def query_arrival_star(system):
+  thread = threading.Thread(target = edsm_query, name = 'EDSM query', args = (system,))
+  thread.daemon = True
+  thread.start()
+
+def edsm_query(system):
+  if not this.edsm_session:
+    this.edsm_session = requests.Session()
+
+  try:
+    arrival_star_checking()
+    r = this.edsm_session.get('https://www.edsm.net/api-v1/system/systemName/{}/showPrimaryStar/1'.format(urllib2.quote(system)), timeout=10)
+    r.raise_for_status()
+    this.edsm_data = r.json()
+    this.frame.event_generate('<<MissingArrivalStar>>', when='tail')
+  except:
+    arrival_star_error()
+    this.edsm_data = None
+
+def edsm_callback(event):
+  if this.edsm_data is not None:
+    star = this.edsm_data.get('primaryStar', None)
+    if star is None:
+      arrival_star_unknown()
+    else:
+      arrival_star_known(star['type'])