From 585153e84ba3434f37c5a575e09ad7d28496d784 Mon Sep 17 00:00:00 2001 From: Michael Clemens Date: Fri, 20 May 2022 18:05:10 +0200 Subject: [PATCH] moved all files to ~/.config/colorspot/ --- setup.cfg | 3 +-- src/colorspot/__init__.py | 2 +- src/colorspot/__main__.py | 41 +++++++++++++++++++++++---------------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/setup.cfg b/setup.cfg index 66fd331..15c811e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = colorspot -version = 0.1.1 +version = 0.1.3 author = Michael Clemens author_email = colorspot@qrz.is description = A colorful CLI DX cluster client with LotW integration @@ -23,7 +23,6 @@ python_requires = >=3.6 install_requires= colored requests - zipfile [options.packages.find] where = src diff --git a/src/colorspot/__init__.py b/src/colorspot/__init__.py index 833913f..daf546e 100644 --- a/src/colorspot/__init__.py +++ b/src/colorspot/__init__.py @@ -1,3 +1,3 @@ from colorspot.__main__ import ColorSpot -__version__ = '0.1.1' +__version__ = '0.1.3' diff --git a/src/colorspot/__main__.py b/src/colorspot/__main__.py index 9850a0c..4dbffe5 100755 --- a/src/colorspot/__main__.py +++ b/src/colorspot/__main__.py @@ -37,6 +37,7 @@ import zipfile from telnetlib import Telnet import requests from colored import fg, bg, attr +from pathlib import Path class ColorSpot(): """ColorSpot class""" @@ -47,7 +48,11 @@ class ColorSpot(): self.print_banner() self.config = configparser.ConfigParser() - self.config_file = os.path.expanduser('~/.colorspot.ini') + self.home_dir = str(Path.home()) + self.config_dir = self.home_dir + "/.config/colorspot/" + # Check if config directory exists and else create it + Path(self.config_dir).mkdir(parents=True, exist_ok=True) + self.config_file = os.path.expanduser(self.config_dir + 'colorspot.ini') self.read_config(self.config, self.config_file) self.check_files() @@ -56,7 +61,7 @@ class ColorSpot(): self.confirmed_entities = self.get_confirmed_entities() if self.check_cty: - with open(self.config['files']['cty'], encoding='us-ascii') as csvfile: + with open(self.config_dir + self.config['files']['cty'], encoding='us-ascii') as csvfile: self.cty = list(csv.reader(csvfile, delimiter=',')) @@ -156,10 +161,11 @@ class ColorSpot(): def check_files(self): """Checks if all necessary files are in the file system. Downloads all files and unzips them (if necessary)""" + # check for lotw qsl information file - self.check_lotw_confirmed = exists(self.config['files']['lotw_confirmed']) + self.check_lotw_confirmed = exists(self.config_dir + self.config['files']['lotw_confirmed']) if not self.check_lotw_confirmed: - print("The file " + self.config['files']['lotw_confirmed'] + " is missing.") + print("The file " + self.config_dir + self.config['files']['lotw_confirmed'] + " is missing.") user = self.config['lotw']['user'] password = self.config['lotw']['password'] mode = self.config['lotw']['mode'] @@ -167,37 +173,38 @@ class ColorSpot(): "&qso_query=1&qso_qsl=yes&qso_mode={}&qso_qsldetail=yes&"\ "qso_qslsince=1970-01-01".format(user, password, mode) print("Trying to download " + url) - self.download_file(url, self.config['files']['lotw_confirmed']) - self.check_lotw_confirmed = exists(self.config['files']['lotw_confirmed']) + self.download_file(url, self.config_dir + self.config['files']['lotw_confirmed']) + self.check_lotw_confirmed = exists(self.config_dir + self.config['files']['lotw_confirmed']) if self.check_lotw_confirmed: print("File successfully downloaded") else: print("something went wrong while downloading " + url) # check for cty.csv file - self.check_cty = exists(self.config['files']['cty']) + self.check_cty = exists(self.config_dir + self.config['files']['cty']) if not self.check_cty: url = self.config['files']['cty_url'] - print("The file " + self.config['files']['cty'] + " is missing.") + print("The file " + self.config_dir + self.config['files']['cty'] + " is missing.") print("Trying to download " + url) - zip_name = self.download_file(url, "bigcty.zip" ) + # TODO: pfad? + zip_name = self.download_file(url, self.config_dir + "bigcty.zip" ) with zipfile.ZipFile(zip_name, 'r') as zip_ref: - zip_ref.extract("cty.csv") + zip_ref.extract("cty.csv", path=self.config_dir) os.remove(zip_name) - self.check_cty = exists(self.config['files']['cty']) + self.check_cty = exists(self.config_dir + self.config['files']['cty']) if self.check_cty: print("File successfully downloaded and extracted.") else: print("something went wrong while downloading " + url) # check for lotw user activity file - self.check_lotw_activity = exists(self.config['files']['lotw_activity']) + self.check_lotw_activity = exists(self.config_dir + self.config['files']['lotw_activity']) if not self.check_lotw_activity: url = self.config['files']['lotw_activity_url'] - print("The file " + self.config['files']['lotw_activity'] + " is missing.") + print("The file " + self.config_dir + self.config['files']['lotw_activity'] + " is missing.") print("Trying to download " + url) - self.download_file(url, self.config['files']['lotw_activity']) - self.check_lotw_activity = exists(self.config['files']['lotw_activity']) + self.download_file(url, self.config_dir + self.config['files']['lotw_activity']) + self.check_lotw_activity = exists(self.config_dir + self.config['files']['lotw_activity']) if self.check_lotw_activity: print("File successfully downloaded") else: @@ -208,7 +215,7 @@ class ColorSpot(): """Reads the file downlaoded from LotW with all confirmed QSOs, extracts all confirmed DXCCs and puts them into a list""" ret = [] - with open(self.config['files']['lotw_confirmed'], encoding='us-ascii') as file: + with open(self.config_dir + self.config['files']['lotw_confirmed'], encoding='us-ascii') as file: for row in file: if re.search("")[2].lower().rstrip() @@ -221,7 +228,7 @@ class ColorSpot(): """Reads the LotW user activity file and returns the date of the last upload date if a specific call sign""" ret = "" - with open(self.config['files']['lotw_activity'], encoding='us-ascii') as csvfile: + with open(self.config_dir + self.config['files']['lotw_activity'], encoding='us-ascii') as csvfile: csv_file = csv.reader(csvfile, delimiter=',') #loop through the csv file for row in csv_file: