Skip to content

Commit

Permalink
clean up imports
Browse files Browse the repository at this point in the history
convert various % and .format to f-strings
  • Loading branch information
n1kdo committed Aug 25, 2024
1 parent 76ede1f commit 44d91f5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 28 deletions.
34 changes: 17 additions & 17 deletions adif.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import re
import time
import urllib.error
import urllib.parse
Expand All @@ -24,10 +23,11 @@
MODES = ['CW', 'DATA', 'IMAGE', 'PHONE']

"""
list of DXCC countries.
dict of DXCC countries.
key is DXCC number
value is tuple (name, deleted)
"""
# noinspection SpellCheckingInspection
dxcc_countries = {
'0': ('None', False),
'1': ('Canada', False),
Expand Down Expand Up @@ -458,7 +458,7 @@
def adif_mode_to_lotw_modegroup(adif_mode):
lotw_modegroup = adif_mode_to_lotw_modegroup_map.get(adif_mode.upper())
if lotw_modegroup is None:
logging.warning('cannot find lotw mode group for adif mode {}, guessing this is DATA'.format(adif_mode))
logging.warning(f'cannot find lotw mode group for adif mode {adif_mode}, guessing this is DATA')
lotw_modegroup = 'DATA'
return lotw_modegroup

Expand Down Expand Up @@ -620,7 +620,7 @@ def read_adif_file(adif_file_name):
:param adif_file_name: the name of the file to read.
:return: adif header as dict, array of QSO data as list of dicts
"""
logging.info('reading adif file {}'.format(adif_file_name))
logging.info(f'reading adif file {adif_file_name}')
qsos = []
header = {}
qso = {}
Expand Down Expand Up @@ -684,10 +684,10 @@ def read_adif_file(adif_file_name):
qso[element_name.lower()] = element_value
state = 0 # start new adif value.
except FileNotFoundError as fnfe:
logging.warning('could not read file {}'.format(adif_file_name))
logging.warning(f'could not read file {adif_file_name}')
logging.warning(fnfe)
logging.info('read {} QSOs from {}'.format(len(qsos), adif_file_name))
return header, sorted(qsos, key=lambda qso: qso_key(qso))
logging.info(f'read {len(qsos)} QSOs from {adif_file_name}')
return header, sorted(qsos, key=lambda sort_qso: qso_key(sort_qso))


def compare_qsos(qso1, qso2):
Expand Down Expand Up @@ -739,7 +739,7 @@ def merge(header, qsos, new_qsos):
if found_qso.get(key) != new_qso.get(key):
updated = True
found_qso[key] = new_qso.get(key)
logging.debug('updating {} with {}'.format(key, new_qso.get(key)))
logging.debug(f'updating {key} with {new_qso.get(key)}')
if updated:
updated_count += 1
logging.debug('updated QSO: ' + str(found_qso))
Expand All @@ -749,20 +749,20 @@ def merge(header, qsos, new_qsos):
logging.debug('ignoring QSO: ' + str(new_qso))

header['app_lotw_numrec'] = str(len(qsos))
logging.info('Added {}, updated {} QSOs'.format(added_count, updated_count))
logging.info(f'Added {added_count}, updated {updated_count} QSOs')
return header, sorted(qsos, key=lambda qso: qso_key(qso))


def write_adif_field(key, item):
if item is not None:
ss = str(item)
return '<{0}:{1}>{2}\n'.format(key, len(ss), ss)
return f'<{key}:{len(ss)}>{ss}\n'
else:
return '<{0}>\n'.format(key)
return f'<{key}>\n'


def write_adif_file(header, qsos, adif_file_name, abridge_results=True):
logging.info('write_adif_file %s' % adif_file_name)
logging.info(f'write_adif_file {adif_file_name}')
save_keys = ['app_lotw_mode',
'app_lotw_modegroup',
'app_n1kdo_qso_combined',
Expand Down Expand Up @@ -821,11 +821,11 @@ def write_adif_file(header, qsos, adif_file_name, abridge_results=True):
f.write(write_adif_field(key, value))
else:
if key not in ignore_keys:
logging.warning('not saving %s %s' % (key, value))
logging.warning(f'not saving {key} {value}')
else:
f.write(write_adif_field(key, value))
f.write('<eor>\n\n')
logging.info('wrote_adif_file %s' % adif_file_name)
logging.info(f'wrote_adif_file {adif_file_name}')


def compare_lists(qso_list, cards_list):
Expand Down Expand Up @@ -856,19 +856,19 @@ def combine_qsos(qso_list, qsl_cards):
if qsl_rcvd != 'y':
break
if found: # have already seen this qsl
logging.warning('already seen {} {} {} '.format(card_merge_key, str(qso), str(card)))
logging.warning(f'already seen {card_merge_key} {str(qso)} {str(card)} ')
found = True
for k in card:
if k not in merge_key_parts:
qso[k] = card[k]
updated_qsls.append(qso)
if not found:
# logging.info('QSL added from card: %s %s %s %s' % (card['call'], card['band'], card['qso_date'], card['country']))
# logging.info(f'QSL added from card: {card["call"]} {card["band"]} {card["qso_date"]} {card["country"]}')
card['app_n1kdo_qso_combined'] = 'qslcards QSL added'
card['qsl_rcvd'] = 'y'
added_qsls.append(card)
qso_list.append(card)
logging.info('updated %d QSL from cards, added %d QSLs from cards' % (len(updated_qsls), len(added_qsls)))
logging.info(f'updated {len(updated_qsls)} QSL from cards, added {len(added_qsls)} QSLs from cards')
return qso_list


Expand Down
7 changes: 3 additions & 4 deletions adif_log_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,15 @@
import datetime
import logging
import os
import sys
import time

import adif
import qso_charts

__author__ = 'Jeffrey B. Otterson, N1KDO'
__copyright__ = 'Copyright 2017 - 2023 Jeffrey B. Otterson'
__copyright__ = 'Copyright 2017 - 2024 Jeffrey B. Otterson'
__license__ = 'Simplified BSD'
__version__ = '0.12.00'
__version__ = '0.12.01'

FFMA_GRIDS = ['CM79', 'CM86', 'CM87', 'CM88', 'CM89', 'CM93', 'CM94', 'CM95', 'CM96', 'CM97', 'CM98', 'CM99',
'CN70', 'CN71', 'CN72', 'CN73', 'CN74', 'CN75', 'CN76', 'CN77', 'CN78', 'CN80', 'CN81', 'CN82',
Expand Down Expand Up @@ -601,7 +600,7 @@ def main():
year = args.marathon_year
try:
year_int = int(year)
except Exception as exc:
except ValueError:
year_int = 0
if year_int < 1900 or year_int > 2199:
logging.error(f'invalid year {year_int}')
Expand Down
1 change: 0 additions & 1 deletion get_lotw_adif.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def get_password(password):
if password is not None and len(password) >= 6:
return password
while True:
# password = getpass.getpass(prompt='Enter your LoTW Password: ')
password = input('Enter your LoTW Password: ')
if password is not None and len(password) > 0:
return password
Expand Down
11 changes: 5 additions & 6 deletions qso_charts.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import datetime
import logging
import numpy as np
import matplotlib
from matplotlib.dates import DateFormatter, YearLocator, MonthLocator, DayLocator, HourLocator
from matplotlib.dates import DateFormatter, YearLocator, MonthLocator, DayLocator, HourLocator, date2num

import matplotlib.pyplot as plt
import matplotlib.backends.backend_agg as agg
Expand Down Expand Up @@ -190,7 +189,7 @@ def __init__(self, bin_data, title, filename=None, start_date=None, end_date=Non

super().__init__(bin_data, title, filename, start_date, end_date, upper)

plot_dates = matplotlib.dates.date2num(qso_dates)
plot_dates = date2num(qso_dates)
colors = ['#ffff00', '#ff9933', '#cc6600', '#660000']
labels = [f'{dxcc} dxcc', f'{challenge} challenge', f'{confirmed} confirmed', f'{worked} logged']

Expand Down Expand Up @@ -221,7 +220,7 @@ def __init__(self, bin_data, title, filename=None, start_date=None, end_date=Non

number_dxcc = bin_data.data[-1]['total_dxcc']
number_challenge = bin_data.data[-1]['total_challenge']
plot_dates = matplotlib.dates.date2num(dates)
plot_dates = date2num(dates)

super().__init__(bin_data, title, filename, start_date, end_date, 0)

Expand Down Expand Up @@ -276,7 +275,7 @@ def __init__(self, bin_data, title, filename=None, start_date=None, end_date=Non
number_vucc = bin_data.data[-1]['total_vucc']
number_ffma = bin_data.data[-1]['total_ffma']

plot_dates = matplotlib.dates.date2num(dates)
plot_dates = date2num(dates)

limit_factor = 500
limit = (int(number_vucc / limit_factor) + 1) * limit_factor
Expand Down Expand Up @@ -340,7 +339,7 @@ def __init__(self, bin_data, title, filename=None, start_date=None, end_date=Non

scale_factor = 50
y_end = (int(biggest / scale_factor) + 1) * scale_factor
plot_dates = matplotlib.dates.date2num(data[0])
plot_dates = date2num(data[0])

super().__init__(bin_data, title, filename, start_date, end_date, 0)

Expand Down

0 comments on commit 44d91f5

Please sign in to comment.