mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-07 10:53:26 +03:00
autoformat with autopep8
This commit is contained in:
parent
3dab0e9d91
commit
eec4c2ebd6
@ -67,6 +67,7 @@ this.station = None
|
|||||||
this.station_marketid = None
|
this.station_marketid = None
|
||||||
STATION_UNDOCKED: str = '×' # "Station" name to display when not docked = U+00D7
|
STATION_UNDOCKED: str = '×' # "Station" name to display when not docked = U+00D7
|
||||||
|
|
||||||
|
|
||||||
def system_url(system_name):
|
def system_url(system_name):
|
||||||
if this.system_address:
|
if this.system_address:
|
||||||
return requests.utils.requote_uri(f'https://inara.cz/galaxy-starsystem/?search={this.system_address}')
|
return requests.utils.requote_uri(f'https://inara.cz/galaxy-starsystem/?search={this.system_address}')
|
||||||
@ -76,6 +77,7 @@ def system_url(system_name):
|
|||||||
|
|
||||||
return this.system
|
return this.system
|
||||||
|
|
||||||
|
|
||||||
def station_url(system_name, station_name):
|
def station_url(system_name, station_name):
|
||||||
if system_name:
|
if system_name:
|
||||||
if station_name:
|
if station_name:
|
||||||
@ -86,7 +88,7 @@ def station_url(system_name, station_name):
|
|||||||
|
|
||||||
|
|
||||||
def plugin_start3(plugin_dir):
|
def plugin_start3(plugin_dir):
|
||||||
this.thread = Thread(target = worker, name = 'Inara worker')
|
this.thread = Thread(target=worker, name='Inara worker')
|
||||||
this.thread.daemon = True
|
this.thread.daemon = True
|
||||||
this.thread.start()
|
this.thread.start()
|
||||||
|
|
||||||
@ -95,12 +97,14 @@ def plugin_start3(plugin_dir):
|
|||||||
this.timer_thread.start()
|
this.timer_thread.start()
|
||||||
return 'Inara'
|
return 'Inara'
|
||||||
|
|
||||||
|
|
||||||
def plugin_app(parent):
|
def plugin_app(parent):
|
||||||
this.system_link = parent.children['system'] # system label in main window
|
this.system_link = parent.children['system'] # system label in main window
|
||||||
this.station_link = parent.children['station'] # station label in main window
|
this.station_link = parent.children['station'] # station label in main window
|
||||||
this.system_link.bind_all('<<InaraLocation>>', update_location)
|
this.system_link.bind_all('<<InaraLocation>>', update_location)
|
||||||
this.system_link.bind_all('<<InaraShip>>', update_ship)
|
this.system_link.bind_all('<<InaraShip>>', update_ship)
|
||||||
|
|
||||||
|
|
||||||
def plugin_stop():
|
def plugin_stop():
|
||||||
# Send any unsent events
|
# Send any unsent events
|
||||||
call()
|
call()
|
||||||
@ -112,8 +116,8 @@ def plugin_stop():
|
|||||||
|
|
||||||
this.timer_run = False
|
this.timer_run = False
|
||||||
|
|
||||||
def plugin_prefs(parent, cmdr, is_beta):
|
|
||||||
|
|
||||||
|
def plugin_prefs(parent, cmdr, is_beta):
|
||||||
PADX = 10
|
PADX = 10
|
||||||
BUTTONX = 12 # indent Checkbuttons and Radiobuttons
|
BUTTONX = 12 # indent Checkbuttons and Radiobuttons
|
||||||
PADY = 2 # close spacing
|
PADY = 2 # close spacing
|
||||||
@ -139,6 +143,7 @@ def plugin_prefs(parent, cmdr, is_beta):
|
|||||||
|
|
||||||
return frame
|
return frame
|
||||||
|
|
||||||
|
|
||||||
def prefs_cmdr_changed(cmdr, is_beta):
|
def prefs_cmdr_changed(cmdr, is_beta):
|
||||||
this.log_button['state'] = cmdr and not is_beta and tk.NORMAL or tk.DISABLED
|
this.log_button['state'] = cmdr and not is_beta and tk.NORMAL or tk.DISABLED
|
||||||
this.apikey['state'] = tk.NORMAL
|
this.apikey['state'] = tk.NORMAL
|
||||||
@ -149,9 +154,11 @@ def prefs_cmdr_changed(cmdr, is_beta):
|
|||||||
this.apikey.insert(0, cred)
|
this.apikey.insert(0, cred)
|
||||||
this.label['state'] = this.apikey_label['state'] = this.apikey['state'] = cmdr and not is_beta and this.log.get() and tk.NORMAL or tk.DISABLED
|
this.label['state'] = this.apikey_label['state'] = this.apikey['state'] = cmdr and not is_beta and this.log.get() and tk.NORMAL or tk.DISABLED
|
||||||
|
|
||||||
|
|
||||||
def prefsvarchanged():
|
def prefsvarchanged():
|
||||||
this.label['state'] = this.apikey_label['state'] = this.apikey['state'] = this.log.get() and this.log_button['state'] or tk.DISABLED
|
this.label['state'] = this.apikey_label['state'] = this.apikey['state'] = this.log.get() and this.log_button['state'] or tk.DISABLED
|
||||||
|
|
||||||
|
|
||||||
def prefs_changed(cmdr, is_beta):
|
def prefs_changed(cmdr, is_beta):
|
||||||
changed = config.getint('inara_out') != this.log.get()
|
changed = config.getint('inara_out') != this.log.get()
|
||||||
config.set('inara_out', this.log.get())
|
config.set('inara_out', this.log.get())
|
||||||
@ -180,9 +187,10 @@ def prefs_changed(cmdr, is_beta):
|
|||||||
|
|
||||||
if this.log.get() and changed:
|
if this.log.get() and changed:
|
||||||
this.newuser = True # Send basic info at next Journal event
|
this.newuser = True # Send basic info at next Journal event
|
||||||
add_event('getCommanderProfile', time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()), { 'searchName': cmdr })
|
add_event('getCommanderProfile', time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()), {'searchName': cmdr})
|
||||||
call()
|
call()
|
||||||
|
|
||||||
|
|
||||||
def credentials(cmdr):
|
def credentials(cmdr):
|
||||||
# Credentials for cmdr
|
# Credentials for cmdr
|
||||||
if not cmdr:
|
if not cmdr:
|
||||||
@ -271,14 +279,14 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
|||||||
('rankName', k.lower()),
|
('rankName', k.lower()),
|
||||||
('rankValue', v[0]),
|
('rankValue', v[0]),
|
||||||
('rankProgress', v[1] / 100.0),
|
('rankProgress', v[1] / 100.0),
|
||||||
]) for k,v in state['Rank'].items() if v is not None
|
]) for k, v in state['Rank'].items() if v is not None
|
||||||
])
|
])
|
||||||
add_event('setCommanderReputationMajorFaction', entry['timestamp'],
|
add_event('setCommanderReputationMajorFaction', entry['timestamp'],
|
||||||
[
|
[
|
||||||
OrderedDict([
|
OrderedDict([
|
||||||
('majorfactionName', k.lower()),
|
('majorfactionName', k.lower()),
|
||||||
('majorfactionReputation', v / 100.0),
|
('majorfactionReputation', v / 100.0),
|
||||||
]) for k,v in state['Reputation'].items() if v is not None
|
]) for k, v in state['Reputation'].items() if v is not None
|
||||||
])
|
])
|
||||||
if state['Engineers']: # Not populated < 3.3
|
if state['Engineers']: # Not populated < 3.3
|
||||||
add_event('setCommanderRankEngineer', entry['timestamp'],
|
add_event('setCommanderRankEngineer', entry['timestamp'],
|
||||||
@ -286,7 +294,7 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
|||||||
OrderedDict([
|
OrderedDict([
|
||||||
('engineerName', k),
|
('engineerName', k),
|
||||||
type(v) is tuple and ('rankValue', v[0]) or ('rankStage', v),
|
type(v) is tuple and ('rankValue', v[0]) or ('rankStage', v),
|
||||||
]) for k,v in state['Engineers'].items()
|
]) for k, v in state['Engineers'].items()
|
||||||
])
|
])
|
||||||
|
|
||||||
# Update location
|
# Update location
|
||||||
@ -317,10 +325,9 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
|||||||
|
|
||||||
call() # Call here just to be sure that if we can send, we do, otherwise it'll get it in the next tick
|
call() # Call here just to be sure that if we can send, we do, otherwise it'll get it in the next tick
|
||||||
|
|
||||||
|
|
||||||
# Promotions
|
# Promotions
|
||||||
elif entry['event'] == 'Promotion':
|
elif entry['event'] == 'Promotion':
|
||||||
for k,v in state['Rank'].items():
|
for k, v in state['Rank'].items():
|
||||||
if k in entry:
|
if k in entry:
|
||||||
add_event('setCommanderRankPilot', entry['timestamp'],
|
add_event('setCommanderRankPilot', entry['timestamp'],
|
||||||
OrderedDict([
|
OrderedDict([
|
||||||
@ -442,7 +449,6 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
|||||||
# Ignore the following 'Docked' event
|
# Ignore the following 'Docked' event
|
||||||
this.suppress_docked = True
|
this.suppress_docked = True
|
||||||
|
|
||||||
|
|
||||||
cargo = [OrderedDict([('itemName', k), ('itemCount', state['Cargo'][k])]) for k in sorted(state['Cargo'])]
|
cargo = [OrderedDict([('itemName', k), ('itemCount', state['Cargo'][k])]) for k in sorted(state['Cargo'])]
|
||||||
|
|
||||||
# Send cargo and materials if changed
|
# Send cargo and materials if changed
|
||||||
@ -451,7 +457,8 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
|||||||
this.cargo = cargo
|
this.cargo = cargo
|
||||||
materials = []
|
materials = []
|
||||||
for category in ['Raw', 'Manufactured', 'Encoded']:
|
for category in ['Raw', 'Manufactured', 'Encoded']:
|
||||||
materials.extend([ OrderedDict([('itemName', k), ('itemCount', state[category][k])]) for k in sorted(state[category]) ])
|
materials.extend([OrderedDict([('itemName', k), ('itemCount', state[category][k])])
|
||||||
|
for k in sorted(state[category])])
|
||||||
if this.materials != materials:
|
if this.materials != materials:
|
||||||
add_event('setCommanderInventoryMaterials', entry['timestamp'], materials)
|
add_event('setCommanderInventoryMaterials', entry['timestamp'], materials)
|
||||||
this.materials = materials
|
this.materials = materials
|
||||||
@ -538,7 +545,7 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
|||||||
'starsystemName': x.get('StarSystem'), # Not present for ships in transit
|
'starsystemName': x.get('StarSystem'), # Not present for ships in transit
|
||||||
'marketID': x.get('ShipMarketID'), # "
|
'marketID': x.get('ShipMarketID'), # "
|
||||||
} for x in entry['ShipsRemote']],
|
} for x in entry['ShipsRemote']],
|
||||||
key = itemgetter('shipGameID')
|
key=itemgetter('shipGameID')
|
||||||
)
|
)
|
||||||
if this.fleet != fleet:
|
if this.fleet != fleet:
|
||||||
this.fleet = fleet
|
this.fleet = fleet
|
||||||
@ -584,7 +591,8 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
|||||||
if this.storedmodules != modules:
|
if this.storedmodules != modules:
|
||||||
# Only send on change
|
# Only send on change
|
||||||
this.storedmodules = modules
|
this.storedmodules = modules
|
||||||
this.events = [x for x in this.events if x['eventName'] != 'setCommanderStorageModules'] # Remove any unsent
|
this.events = [x for x in this.events if x['eventName']
|
||||||
|
!= 'setCommanderStorageModules'] # Remove any unsent
|
||||||
add_event('setCommanderStorageModules', entry['timestamp'], this.storedmodules)
|
add_event('setCommanderStorageModules', entry['timestamp'], this.storedmodules)
|
||||||
|
|
||||||
# Missions
|
# Missions
|
||||||
@ -619,26 +627,28 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
|||||||
add_event('addCommanderMission', entry['timestamp'], data)
|
add_event('addCommanderMission', entry['timestamp'], data)
|
||||||
|
|
||||||
elif entry['event'] == 'MissionAbandoned':
|
elif entry['event'] == 'MissionAbandoned':
|
||||||
add_event('setCommanderMissionAbandoned', entry['timestamp'], { 'missionGameID': entry['MissionID'] })
|
add_event('setCommanderMissionAbandoned', entry['timestamp'], {'missionGameID': entry['MissionID']})
|
||||||
|
|
||||||
elif entry['event'] == 'MissionCompleted':
|
elif entry['event'] == 'MissionCompleted':
|
||||||
for x in entry.get('PermitsAwarded', []):
|
for x in entry.get('PermitsAwarded', []):
|
||||||
add_event('addCommanderPermit', entry['timestamp'], { 'starsystemName': x })
|
add_event('addCommanderPermit', entry['timestamp'], {'starsystemName': x})
|
||||||
|
|
||||||
data = OrderedDict([ ('missionGameID', entry['MissionID']) ])
|
data = OrderedDict([('missionGameID', entry['MissionID'])])
|
||||||
if 'Donation' in entry:
|
if 'Donation' in entry:
|
||||||
data['donationCredits'] = entry['Donation']
|
data['donationCredits'] = entry['Donation']
|
||||||
if 'Reward' in entry:
|
if 'Reward' in entry:
|
||||||
data['rewardCredits'] = entry['Reward']
|
data['rewardCredits'] = entry['Reward']
|
||||||
if 'PermitsAwarded' in entry:
|
if 'PermitsAwarded' in entry:
|
||||||
data['rewardPermits'] = [{ 'starsystemName': x } for x in entry['PermitsAwarded']]
|
data['rewardPermits'] = [{'starsystemName': x} for x in entry['PermitsAwarded']]
|
||||||
if 'CommodityReward' in entry:
|
if 'CommodityReward' in entry:
|
||||||
data['rewardCommodities'] = [{ 'itemName': x['Name'], 'itemCount': x['Count'] } for x in entry['CommodityReward']]
|
data['rewardCommodities'] = [{'itemName': x['Name'], 'itemCount': x['Count']}
|
||||||
|
for x in entry['CommodityReward']]
|
||||||
if 'MaterialsReward' in entry:
|
if 'MaterialsReward' in entry:
|
||||||
data['rewardMaterials'] = [{ 'itemName': x['Name'], 'itemCount': x['Count'] } for x in entry['MaterialsReward']]
|
data['rewardMaterials'] = [{'itemName': x['Name'], 'itemCount': x['Count']}
|
||||||
|
for x in entry['MaterialsReward']]
|
||||||
factioneffects = []
|
factioneffects = []
|
||||||
for faction in entry.get('FactionEffects', []):
|
for faction in entry.get('FactionEffects', []):
|
||||||
effect = OrderedDict([ ('minorfactionName', faction['Faction']) ])
|
effect = OrderedDict([('minorfactionName', faction['Faction'])])
|
||||||
for influence in faction.get('Influence', []):
|
for influence in faction.get('Influence', []):
|
||||||
if 'Influence' in influence:
|
if 'Influence' in influence:
|
||||||
effect['influenceGain'] = len(effect.get('influenceGain', '')) > len(influence['Influence']) and effect['influenceGain'] or influence['Influence'] # pick highest
|
effect['influenceGain'] = len(effect.get('influenceGain', '')) > len(influence['Influence']) and effect['influenceGain'] or influence['Influence'] # pick highest
|
||||||
@ -650,11 +660,11 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
|||||||
add_event('setCommanderMissionCompleted', entry['timestamp'], data)
|
add_event('setCommanderMissionCompleted', entry['timestamp'], data)
|
||||||
|
|
||||||
elif entry['event'] == 'MissionFailed':
|
elif entry['event'] == 'MissionFailed':
|
||||||
add_event('setCommanderMissionFailed', entry['timestamp'], { 'missionGameID': entry['MissionID'] })
|
add_event('setCommanderMissionFailed', entry['timestamp'], {'missionGameID': entry['MissionID']})
|
||||||
|
|
||||||
# Combat
|
# Combat
|
||||||
if entry['event'] == 'Died':
|
if entry['event'] == 'Died':
|
||||||
data = OrderedDict([ ('starsystemName', system) ])
|
data = OrderedDict([('starsystemName', system)])
|
||||||
if 'Killers' in entry:
|
if 'Killers' in entry:
|
||||||
data['wingOpponentNames'] = [x['Name'] for x in entry['Killers']]
|
data['wingOpponentNames'] = [x['Name'] for x in entry['Killers']]
|
||||||
elif 'KillerName' in entry:
|
elif 'KillerName' in entry:
|
||||||
@ -702,7 +712,8 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
|||||||
|
|
||||||
# Community Goals
|
# Community Goals
|
||||||
if entry['event'] == 'CommunityGoal':
|
if entry['event'] == 'CommunityGoal':
|
||||||
this.events = [x for x in this.events if x['eventName'] not in ['setCommunityGoal', 'setCommanderCommunityGoalProgress']] # Remove any unsent
|
this.events = [x for x in this.events if x['eventName'] not in [
|
||||||
|
'setCommunityGoal', 'setCommanderCommunityGoalProgress']] # Remove any unsent
|
||||||
for goal in entry['CurrentGoals']:
|
for goal in entry['CurrentGoals']:
|
||||||
|
|
||||||
data = OrderedDict([
|
data = OrderedDict([
|
||||||
@ -761,6 +772,7 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
|||||||
this.station_link['url'] = station_url(this.system, this.station)
|
this.station_link['url'] = station_url(this.system, this.station)
|
||||||
this.station_link.update_idletasks()
|
this.station_link.update_idletasks()
|
||||||
|
|
||||||
|
|
||||||
def cmdr_data(data, is_beta):
|
def cmdr_data(data, is_beta):
|
||||||
this.cmdr = data['commander']['name']
|
this.cmdr = data['commander']['name']
|
||||||
|
|
||||||
@ -846,6 +858,7 @@ def make_loadout(state):
|
|||||||
('shipLoadout', modules),
|
('shipLoadout', modules),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
def add_event(name, timestamp, data):
|
def add_event(name, timestamp, data):
|
||||||
this.events.append(OrderedDict([
|
this.events.append(OrderedDict([
|
||||||
('eventName', name),
|
('eventName', name),
|
||||||
@ -853,6 +866,7 @@ def add_event(name, timestamp, data):
|
|||||||
('eventData', data),
|
('eventData', data),
|
||||||
]))
|
]))
|
||||||
|
|
||||||
|
|
||||||
def call_timer(wait=FLOOD_LIMIT_SECONDS):
|
def call_timer(wait=FLOOD_LIMIT_SECONDS):
|
||||||
while this.timer_run:
|
while this.timer_run:
|
||||||
time.sleep(wait)
|
time.sleep(wait)
|
||||||
@ -860,6 +874,8 @@ def call_timer(wait=FLOOD_LIMIT_SECONDS):
|
|||||||
call()
|
call()
|
||||||
|
|
||||||
# Queue a call to Inara, handled in Worker thread
|
# Queue a call to Inara, handled in Worker thread
|
||||||
|
|
||||||
|
|
||||||
def call(callback=None, force=False):
|
def call(callback=None, force=False):
|
||||||
if not this.events:
|
if not this.events:
|
||||||
return
|
return
|
||||||
@ -883,6 +899,8 @@ def call(callback=None, force=False):
|
|||||||
this.queue.put(('https://inara.cz/inapi/v1/', data, None))
|
this.queue.put(('https://inara.cz/inapi/v1/', data, None))
|
||||||
|
|
||||||
# Worker thread
|
# Worker thread
|
||||||
|
|
||||||
|
|
||||||
def worker():
|
def worker():
|
||||||
while True:
|
while True:
|
||||||
item = this.queue.get()
|
item = this.queue.get()
|
||||||
@ -894,7 +912,7 @@ def worker():
|
|||||||
retrying = 0
|
retrying = 0
|
||||||
while retrying < 3:
|
while retrying < 3:
|
||||||
try:
|
try:
|
||||||
r = this.session.post(url, data=json.dumps(data, separators = (',', ':')), timeout=_TIMEOUT)
|
r = this.session.post(url, data=json.dumps(data, separators=(',', ':')), timeout=_TIMEOUT)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
reply = r.json()
|
reply = r.json()
|
||||||
status = reply['header']['eventStatus']
|
status = reply['header']['eventStatus']
|
||||||
@ -944,10 +962,13 @@ def update_location(event=None):
|
|||||||
for plugin in plug.provides('inara_notify_location'):
|
for plugin in plug.provides('inara_notify_location'):
|
||||||
plug.invoke(plugin, None, 'inara_notify_location', this.lastlocation)
|
plug.invoke(plugin, None, 'inara_notify_location', this.lastlocation)
|
||||||
|
|
||||||
|
|
||||||
def inara_notify_location(eventData):
|
def inara_notify_location(eventData):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Call inara_notify_ship() in interested plugins with Inara's response when changing ship
|
# Call inara_notify_ship() in interested plugins with Inara's response when changing ship
|
||||||
|
|
||||||
|
|
||||||
def update_ship(event=None):
|
def update_ship(event=None):
|
||||||
if this.lastship:
|
if this.lastship:
|
||||||
for plugin in plug.provides('inara_notify_ship'):
|
for plugin in plug.provides('inara_notify_ship'):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user