diff --git a/colorspot.py b/colorspot.py index 891e40c..158d86f 100755 --- a/colorspot.py +++ b/colorspot.py @@ -32,10 +32,10 @@ class ColorSpot(): self.read_config(self.config, self.config_file) self.check_files() + if self.check_lotw_confirmed: self.confirmed_entities = self.get_confirmed_entities() - if self.check_cty: self.cty = list(csv.reader(open(self.config['files']['cty'], "r"), delimiter=",")) @@ -46,15 +46,10 @@ class ColorSpot(): @staticmethod def download_file(url, local_filename): - #local_filename = url.split('/')[-1] - # NOTE the stream=True parameter below with requests.get(url, stream=True) as r: r.raise_for_status() with open(local_filename, 'wb') as f: for chunk in r.iter_content(chunk_size=8192): - # If you have chunk encoded response uncomment if - # and set chunk_size parameter to None. - #if chunk: f.write(chunk) return local_filename @@ -63,12 +58,24 @@ class ColorSpot(): self.check_lotw_confirmed = exists(self.config['files']['lotw_confirmed']) if not self.check_lotw_confirmed: print("The file " + self.config['files']['lotw_confirmed'] + " is missing.") + user = self.config['lotw']['user'] + password = self.config['lotw']['password'] + mode = self.config['lotw']['mode'] + url = "https://lotw.arrl.org/lotwuser/lotwreport.adi?login={}&password={}&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) + file_name = self.download_file(url, self.config['files']['lotw_confirmed']) + self.check_lotw_confirmed = exists(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']) if not self.check_cty: - url = "https://www.country-files.com/bigcty/download/bigcty.zip" + url = self.config['files']['cty_url'] print("The file " + self.config['files']['cty'] + " is missing.") print("Trying to download " + url) zip_name = self.download_file(url, "bigcty.zip" ) @@ -84,7 +91,7 @@ class ColorSpot(): # check for lotw user activity file self.check_lotw_activity = exists(self.config['files']['lotw_activity']) if not self.check_lotw_activity: - url = "https://lotw.arrl.org/lotw-user-activity.csv" + url = self.config['files']['lotw_activity_url'] print("The file " + self.config['files']['lotw_activity'] + " is missing.") print("Trying to download " + url) file_name = self.download_file(url, self.config['files']['lotw_activity']) @@ -123,8 +130,10 @@ class ColorSpot(): 'timeout': '100'} config['files'] = { 'cty': 'cty.csv', + 'cty_url': 'https://www.country-files.com/bigcty/download/bigcty.zip', 'lotw_confirmed': 'lotw.adi', - 'lotw_activity': 'lotw-user-activity.csv'} + 'lotw_activity': 'lotw-user-activity.csv', + 'lotw_activity_url': 'https://lotw.arrl.org/lotw-user-activity.csv'} config['lotw'] = { 'user': 'N0CALL', 'password': 'XXXXXXXXX',