Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes incorrect locale-based parsing in eddblink #150

Merged
merged 1 commit into from
May 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 2 additions & 27 deletions tradedangerous/plugins/eddblink_plug.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,18 @@
import certifi
import csv
import datetime
from email.utils import parsedate_to_datetime
import os
import requests
import sqlite3
import ssl
import typing
import locale
import platform


if typing.TYPE_CHECKING:
from typing import Optional
from .. tradeenv import TradeEnv

# Find the first English UTF-8 locale for use in parsing timestamps.
LOCALE = None
if platform.system() == 'Windows':
for lang in locale.windows_locale.values():
if "en" in lang:
LOCALE = lang
break
else:
# for other operating systems
for lang in locale.locale_alias.values():
if "en" in lang and "UTF-8" in lang:
LOCALE = lang
break
if not LOCALE:
raise PluginException(
"Unable to find compatible locale.\n" +
"This plugin needs an English, UTF-8 compatible " +
"locale installed in order to function correctly.\n" +
"Please refer to your OS for instructions installing one."
)
# Constants
BASE_URL = os.environ.get('TD_SERVER') or "https://elite.tromador.com/files/"
CONTEXT=ssl.create_default_context(cafile=certifi.where())
Expand Down Expand Up @@ -188,10 +167,8 @@ def downloadFile(self, path):
self.tdenv.WARN("Problem with download:\n URL: {}\n Error: {}", url, str(e))
return False

locale.setlocale(locale.LC_ALL, LOCALE)
last_modified = response.headers.get("last-modified")
dump_mod_time = datetime.datetime.strptime(last_modified, "%a, %d %b %Y %H:%M:%S %Z").timestamp()
locale.setlocale(locale.LC_ALL, '')
dump_mod_time = parsedate_to_datetime(last_modified).timestamp()

if Path.exists(localPath):
local_mod_time = localPath.stat().st_mtime
Expand Down Expand Up @@ -352,8 +329,6 @@ def importListings(self, listings_file):
self.tdenv.NOTE("Finished processing market data. End time = {}", self.now())

def run(self):
self.tdenv.DEBUG2(f'Using "{LOCALE}" locale for parsing modified timestamps. Please include this information in any error reports.')

self.tdenv.ignoreUnknown = True

# Create the /eddb folder for downloading the source files if it doesn't exist.
Expand Down