mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-20 19:07:38 +03:00
system/station providers: Sanitise {system,station}_url logic
* Make all plugins use `requests.utils.requote_uri()` * Make all plugins use roughly the same logic, without if/else trees (as the bodies do a `return ...`), ending with `return ''` if input parameters are None. This throws away the inara fallback to `this.station or this.system` as it's unlikely the in-plugin tracking did a better job than the monitor.py code.
This commit is contained in:
parent
7617ce7e9c
commit
daed08d206
@ -51,20 +51,17 @@ def system_url(system_name: str) -> str:
|
||||
if this.system_address:
|
||||
return requests.utils.requote_uri(f'https://eddb.io/system/ed-address/{this.system_address}')
|
||||
|
||||
elif system_name:
|
||||
if system_name:
|
||||
return requests.utils.requote_uri(f'https://eddb.io/system/name/{system_name}')
|
||||
|
||||
else:
|
||||
return ''
|
||||
return ''
|
||||
|
||||
|
||||
def station_url(system_name: str, station_name: str) -> str:
|
||||
if this.station_marketid:
|
||||
return requests.utils.requote_uri(f'https://eddb.io/station/market-id/{this.station_marketid}')
|
||||
|
||||
else:
|
||||
return system_url('')
|
||||
|
||||
return system_url(system_name)
|
||||
|
||||
def plugin_start3(plugin_dir):
|
||||
return 'eddb'
|
||||
|
@ -14,9 +14,6 @@
|
||||
import json
|
||||
import requests
|
||||
import sys
|
||||
import urllib.request
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
from queue import Queue
|
||||
from threading import Thread
|
||||
import logging
|
||||
@ -60,14 +57,19 @@ STATION_UNDOCKED: str = '×' # "Station" name to display when not docked = U+00
|
||||
|
||||
# Main window clicks
|
||||
def system_url(system_name):
|
||||
return 'https://www.edsm.net/en/system?systemName=%s' % urllib.parse.quote(system_name)
|
||||
if system_name:
|
||||
return requests.utils.requote_uri(f'https://www.edsm.net/en/system?systemName={system_name}')
|
||||
|
||||
return ''
|
||||
|
||||
def station_url(system_name, station_name):
|
||||
if station_name:
|
||||
return 'https://www.edsm.net/en/system?systemName=%s&stationName=%s' % (urllib.parse.quote(system_name), urllib.parse.quote(station_name))
|
||||
else:
|
||||
return 'https://www.edsm.net/en/system?systemName=%s&stationName=ALL' % urllib.parse.quote(system_name)
|
||||
if system_name and station_name:
|
||||
return requests.utils.requote_uri(f'https://www.edsm.net/en/system?systemName={system_name}&stationName={station_name}')
|
||||
|
||||
if system_name:
|
||||
return requests.utils.requote_uri(f'https://www.edsm.net/en/system?systemName={system_name}&stationName=ALL')
|
||||
|
||||
return ''
|
||||
|
||||
def plugin_start3(plugin_dir):
|
||||
# Can't be earlier since can only call PhotoImage after window is created
|
||||
|
@ -133,18 +133,14 @@ def system_url(system_name: str):
|
||||
|
||||
return this.system
|
||||
|
||||
def station_url(system_name, station_name):
|
||||
if system_name and station_name:
|
||||
return requests.utils.requote_uri(f'https://inara.cz/galaxy-station/?search={system_name}%20[{station_name}]')
|
||||
|
||||
def station_url(system_name: Optional[str], station_name: Optional[str]):
|
||||
if system_name:
|
||||
if station_name:
|
||||
return requests.utils.requote_uri(
|
||||
f'https://inara.cz/galaxy-station/?search={system_name}%20[{station_name}]'
|
||||
)
|
||||
|
||||
return system_url(system_name)
|
||||
|
||||
return this.station if this.station else this.system
|
||||
|
||||
return ''
|
||||
|
||||
def plugin_start3(plugin_dir):
|
||||
this.thread = Thread(target=new_worker, name='Inara worker')
|
||||
|
Loading…
x
Reference in New Issue
Block a user