1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-06-05 18:03:17 +03:00

plugins/edsy: flake8 and mypy pass

This commit is contained in:
Athanasius 2022-12-04 16:20:08 +00:00
parent ba81d95c1e
commit a6f9a31fd9
No known key found for this signature in database
GPG Key ID: 772697E181BB2767

View File

@ -1,4 +1,4 @@
# EDShipyard ship export """Export data for ED Shipyard."""
# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# # ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $#
# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# # ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $#
@ -15,25 +15,41 @@
# Thus you **MUST** check if any imports you add in this file are only # Thus you **MUST** check if any imports you add in this file are only
# referenced in this file (or only in any other core plugin), and if so... # referenced in this file (or only in any other core plugin), and if so...
# #
# YOU MUST ENSURE THAT PERTINENT ADJUSTMENTS ARE MADE IN `setup.py` # YOU MUST ENSURE THAT PERTINENT ADJUSTMENTS ARE MADE IN
# SO AS TO ENSURE THE FILES ARE ACTUALLY PRESENT IN AN END-USER # `Build-exe-and-msi.py` SO AS TO ENSURE THE FILES ARE ACTUALLY PRESENT IN
# INSTALLATION ON WINDOWS. # AN END-USER INSTALLATION ON WINDOWS.
# #
# #
# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# # ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $#
# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# # ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $#
import base64 import base64
import gzip import gzip
import json
import io import io
import json
from typing import Any, Mapping
def plugin_start3(plugin_dir): def plugin_start3(plugin_dir: str) -> str:
"""
Start the plugin.
:param plugin_dir: NAme of directory this was loaded from.
:return: Identifier string for this plugin.
"""
return 'EDSY' return 'EDSY'
# Return a URL for the current ship # Return a URL for the current ship
def shipyard_url(loadout, is_beta): def shipyard_url(loadout: Mapping[str, Any], is_beta) -> bool | str:
string = json.dumps(loadout, ensure_ascii=False, sort_keys=True, separators=(',', ':')).encode('utf-8') # most compact representation """
Construct a URL for ship loadout.
:param loadout:
:param is_beta:
:return:
"""
# most compact representation
string = json.dumps(loadout, ensure_ascii=False, sort_keys=True, separators=(',', ':')).encode('utf-8')
if not string: if not string:
return False return False
@ -41,4 +57,6 @@ def shipyard_url(loadout, is_beta):
with gzip.GzipFile(fileobj=out, mode='w') as f: with gzip.GzipFile(fileobj=out, mode='w') as f:
f.write(string) f.write(string)
return (is_beta and 'http://edsy.org/beta/#/I=' or 'http://edsy.org/#/I=') + base64.urlsafe_b64encode(out.getvalue()).decode().replace('=', '%3D') return (
is_beta and 'http://edsy.org/beta/#/I=' or 'http://edsy.org/#/I='
) + base64.urlsafe_b64encode(out.getvalue()).decode().replace('=', '%3D')