added download of missing files

switched to cty.csv as data source
This commit is contained in:
Michael Clemens 2022-05-20 14:45:09 +02:00
parent 6b4672bd32
commit de323722f4

View File

@ -16,25 +16,85 @@ from colored import fg, bg, attr
import configparser
from collections import defaultdict
import random
import requests
from os.path import exists
import zipfile
class ColorSpot():
def __init__(self):
self.version = "0.1.0"
self.print_banner()
self.config = configparser.ConfigParser()
self.config_file = os.path.expanduser('~/.colorspot.ini')
self.read_config(self.config, self.config_file)
self.qsl_countries = self.get_confirmed_countries()
self.check_files()
if self.check_lotw_confirmed:
self.confirmed_entities = self.get_confirmed_entities()
self.print_banner()
if self.check_cty:
self.cty = list(csv.reader(open(self.config['files']['cty'], "r"), delimiter=","))
@staticmethod
def rnd_col():
r = lambda: random.randint(0,255)
return'#%02X%02X%02X' % (r(),r(),r())
@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
def check_files(self):
# check for lotw qsl information file
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.")
# 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"
print("The file " + self.config['files']['cty'] + " is missing.")
print("Trying to download " + url)
zip_name = self.download_file(url, "bigcty.zip" )
with zipfile.ZipFile(zip_name, 'r') as zip_ref:
zip_ref.extract("cty.csv")
os.remove(zip_name)
self.check_cty = exists(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'])
if not self.check_lotw_activity:
url = "https://lotw.arrl.org/lotw-user-activity.csv"
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'])
self.check_lotw_activity = exists(self.config['files']['lotw_activity'])
if self.check_lotw_activity:
print("File successfully downloaded")
else:
print("something went wrong while downloading " + url)
def print_banner(self):
"""print an awesome banner"""
@ -45,6 +105,7 @@ class ColorSpot():
print(fg(self.rnd_col())+" | (__/ _ \ / _ \ '_\__ \ '_ \/ _ \ _|")
print(fg(self.rnd_col())+" \___\___/_\___/_| |___/ .__/\___/\__|")
print(fg(self.rnd_col())+" -= DK1MI =- |_| ")
print("")
print(attr('reset'))
@staticmethod
@ -60,6 +121,10 @@ class ColorSpot():
'port': '7373',
'user': 'N0CALL',
'timeout': '100'}
config['files'] = {
'cty': 'cty.csv',
'lotw_confirmed': 'lotw.adi',
'lotw_activity': 'lotw-user-activity.csv'}
config['lotw'] = {
'user': 'N0CALL',
'password': 'XXXXXXXXX',
@ -96,653 +161,6 @@ class ColorSpot():
'alert_bg': 'indian_red_1a',
'alert_fg': 'white',
'default_bg': 'black'}
config['dxcc'] = {
"1A": "Sov. Mil. Order of Malta,EU",
"3A": "Monaco,EU",
"3B6": "Agalega & St. Brandon Is.,AF",
"3B7": "Agalega & St. Brandon Is.,AF",
"3B8": "Mauritius,AF",
"3B9": "Rodriguez I.,AF",
"3C": "Equatorial Guinea,AF",
"3C0": "Annobon I.,AF",
"3D2": "Fiji,OC",
"3D2": "Conway Reef,OC",
"3D2": "Rotuma I.,OC",
"3DA": "Swaziland,AF",
"3V": "Tunisia,AF",
"3W": "Viet Nam,AS",
"XV": "Viet Nam,AS",
"3X": "Guinea,AF",
"3Y": "Bouvet,AF",
"3Y": "Peter I I.,AN",
"4J": "Azerbaijan,AS",
"4K": "Azerbaijan,AS",
"4L": "Georgia,AS",
"4O": "Montenegro,EU",
"4S": "Sri Lanka,AS",
"4U_ITU": "ITU HQ,EU",
"4U_UN": "United Nations HQ,NA",
"4W": "Timor - Leste,OC",
"4X": "Israel,AS",
"4Z": "Israel,AS",
"5A": "Libya,AF",
"5B": "Cyprus,AS",
"C4": "Cyprus,AS",
"P3": "Cyprus,AS",
"5H": "Tanzania,AF",
"5I": "Tanzania,AF",
"5N": "Nigeria,AF",
"5R": "Madagascar,AF",
"5T": "Mauritania,AF",
"5U": "Niger,AF",
"5V": "Togo,AF",
"5W": "Samoa,OC",
"5X": "Uganda,AF",
"5Y": "Kenya,AF",
"5Z": "Kenya,AF",
"6V": "Senegal,AF",
"6W": "Senegal,AF",
"6Y": "Jamaica,NA",
"7O": "Yemen,AS",
"7P": "Lesotho,AF",
"7Q": "Malawi,AF",
"7T": "Algeria,AF",
"7U": "Algeria,AF",
"7V": "Algeria,AF",
"7W": "Algeria,AF",
"7X": "Algeria,AF",
"7Y": "Algeria,AF",
"8P": "Barbados,NA",
"8Q": "Maldives,AF",
"8R": "Guyana,SA",
"9A": "Croatia,EU",
"9G": "Ghana,AF",
"9H": "Malta,EU",
"9I": "Zambia,AF",
"9J": "Zambia,AF",
"9K": "Kuwait,AS",
"9L": "Sierra Leone,AF",
"9M2": "West Malaysia,AS",
"9M4": "West Malaysia,AS",
"9M6": "East Malaysia,OC",
"9M8": "East Malaysia,OC",
"9N": "Nepal,AS",
"9Q": "Dem. Rep. of Congo,AF",
"9R": "Dem. Rep. of Congo,AF",
"9S": "Dem. Rep. of Congo,AF",
"9T": "Dem. Rep. of Congo,AF",
"9U": "Burundi,AF",
"9V": "Singapore,AS",
"9X": "Rwanda,AF",
"9Y": "Trinidad & Tobago,SA",
"9Z": "Trinidad & Tobago,SA",
"A2": "Botswana,AF",
"A3": "Tonga,OC",
"A4": "Oman,AS",
"A5": "Bhutan,AS",
"A6": "United Arab Emirates,AS",
"A7": "Qatar,AS",
"A9": "Bahrain,AS",
"AP": "Pakistan,AS",
"B": "China,AS",
"BS7": "Scarborough Reef,AS",
"BV": "Taiwan,AS",
"BV9P": "Pratas I.,AS",
"C2": "Nauru,OC",
"C3": "Andorra,EU",
"C5": "The Gambia,AF",
"C6": "Bahamas,NA",
"C8": "Mozambique,AF",
"C9": "Mozambique,AF",
"CA": "Chile,SA",
"CB": "Chile,SA",
"CC": "Chile,SA",
"CD": "Chile,SA",
"CE": "Chile,SA",
"CE0": "Easter I.,SA",
"CE0": "Juan Fernandez Is.,SA",
"CE0": "San Felix & San Ambrosio,SA",
"CE9": "Antarctica,AN",
"KC4": "Antarctica,AN",
"3Y": "Antarctica,AN",
"8j1": "Antarctica,AN",
"AT0": "Antarctica,AN",
"DP0": "Antarctica,AN",
"VK0": "Antarctica,AN",
"VP8": "Antarctica,AN",
"R1AW": "Antarctica,AN",
"CM": "Cuba,NA",
"CO": "Cuba,NA",
"CN": "Morocco,AF",
"CP": "Bolivia,SA",
"CT": "Portugal,EU",
"CT3": "Madeira Is.,AF",
"CU": "Azores,EU",
"CV": "Uruguay,SA",
"CW": "Uruguay,SA",
"CX": "Uruguay,SA",
"CY0": "Sable I.,NA",
"CY9": "St. Paul I.,NA",
"D2": "Angola,AF",
"D3": "Angola,AF",
"D4": "Cape Verde,AF",
"D6": "Comoros,AF",
"DA": "Federal Republic of Germany,EU",
"DB": "Federal Republic of Germany,EU",
"DC": "Federal Republic of Germany,EU",
"DD": "Federal Republic of Germany,EU",
"DE": "Federal Republic of Germany,EU",
"DF": "Federal Republic of Germany,EU",
"DG": "Federal Republic of Germany,EU",
"DH": "Federal Republic of Germany,EU",
"DI": "Federal Republic of Germany,EU",
"DJ": "Federal Republic of Germany,EU",
"DK": "Federal Republic of Germany,EU",
"DL": "Federal Republic of Germany,EU",
"DM": "Federal Republic of Germany,EU",
"DN": "Federal Republic of Germany,EU",
"DO": "Federal Republic of Germany,EU",
"DP": "Federal Republic of Germany,EU",
"DQ": "Federal Republic of Germany,EU",
"DR": "Federal Republic of Germany,EU",
"DU": "Philippines,OC",
"DV": "Philippines,OC",
"DW": "Philippines,OC",
"DX": "Philippines,OC",
"DY": "Philippines,OC",
"DZ": "Philippines,OC",
"E3": "Eritrea,AF",
"E4": "Palestine,AS",
"E5": "N. Cook Is.,OC",
"E5": "S. Cook Is.,OC",
"E7": "Bosnia-Herzegovina,EU",
"EA": "Spain,EU",
"EB": "Spain,EU",
"EC": "Spain,EU",
"ED": "Spain,EU",
"EE": "Spain,EU",
"EF": "Spain,EU",
"EG": "Spain,EU",
"EH": "Spain,EU",
"EA6": "Balearic Is.,EU",
"EB6": "Balearic Is.,EU",
"EC6": "Balearic Is.,EU",
"ED6": "Balearic Is.,EU",
"EE6": "Balearic Is.,EU",
"EF6": "Balearic Is.,EU",
"EG6": "Balearic Is.,EU",
"EH6": "Balearic Is.,EU",
"EA8": "Canary Is.,AF",
"EB8": "Canary Is.,AF",
"EC8": "Canary Is.,AF",
"ED8": "Canary Is.,AF",
"EE8": "Canary Is.,AF",
"EF8": "Canary Is.,AF",
"EG8": "Canary Is.,AF",
"EH8": "Canary Is.,AF",
"EA9": "Ceuta & Melilla,AF",
"EB9": "Ceuta & Melilla,AF",
"EC9": "Ceuta & Melilla,AF",
"ED9": "Ceuta & Melilla,AF",
"EE9": "Ceuta & Melilla,AF",
"EF9": "Ceuta & Melilla,AF",
"EG9": "Ceuta & Melilla,AF",
"EH9": "Ceuta & Melilla,AF",
"EI": "Ireland,EU",
"EJ": "Ireland,EU",
"EK": "Armenia,AS",
"EL": "Liberia,AF",
"EP": "Iran,AS",
"EQ": "Iran,AS",
"ER": "Moldova,EU",
"ES": "Estonia,EU",
"ET": "Ethiopia,AF",
"EU": "Belarus,EU",
"EV": "Belarus,EU",
"EW": "Belarus,EU",
"EX": "Kyrgyzstan,AS",
"EY": "Tajikistan,AS",
"EZ": "Turkmenistan,AS",
"F": "France,EU",
"FG": "Guadeloupe,NA",
"FH": "Mayotte,AF",
"FJ": "Saint Barthelemy,NA",
"FK": "New Caledonia,OC",
"FK": "Chesterfield Is.,OC",
"FM": "Martinique,NA",
"FO": "Austral I.,OC",
"FO": "Clipperton I.,NA",
"FO": "French Polynesia,OC",
"FO": "Marquesas Is.,OC",
"FP": "St. Pierre & Miquelon,NA",
"FR/G": "Glorioso Is.,AF",
"FR/J": "Juan de Nova, Europa,AF",
"FR/E": "Juan de Nova, Europa,AF",
"FR": "Reunion I.,AF",
"FR/T": "Tromelin I.,AF",
"FS": "Saint Martin,NA",
"FT/W": "Crozet I.,AF",
"FT/X": "Kerguelen Is.,AF",
"FT/Z": "Amsterdam & St. Paul Is.,AF",
"FW": "Wallis & Futuna Is.,OC",
"FY": "French Guiana,SA",
"G": "England,EU",
"GX": "England,EU",
"M": "England,EU",
"GD": "Isle of Man,EU",
"GT": "Isle of Man,EU",
"GI": "Northern Ireland,EU",
"GN": "Northern Ireland,EU",
"GJ": "Jersey,EU",
"GH": "Jersey,EU",
"GM": "Scotland,EU",
"GS": "Scotland,EU",
"GU": "Guernsey,EU",
"GP": "Guernsey,EU",
"GW": "Wales,EU",
"GC": "Wales,EU",
"H4": "Solomon Is.,OC",
"H40": "Temotu Province,OC",
"HA": "Hungary,EU",
"HG": "Hungary,EU",
"HB": "Switzerland,EU",
"HB0": "Liechtenstein,EU",
"HC": "Ecuador,SA",
"HD": "Ecuador,SA",
"HC8": "Galapagos Is.,SA",
"HD8": "Galapagos Is.,SA",
"HH": "Haiti,NA",
"HI": "Dominican Republic,NA",
"HJ": "Colombia,SA",
"HK": "Colombia,SA",
"5J": "Colombia,SA",
"5K": "Colombia,SA",
"HK0": "Malpelo I.,SA",
"HK0": "San Andres & Providencia,NA",
"HL": "Republic of Korea,AS",
"6K": "Republic of Korea,AS",
"6N": "Republic of Korea,AS",
"HO": "Panama,NA",
"HP": "Panama,NA",
"HQ": "Honduras,NA",
"HR": "Honduras,NA",
"HS": "Thailand,AS",
"E2": "Thailand,AS",
"HV": "Vatican,EU",
"HZ": "Saudi Arabia,AS",
"I": "Italy,EU",
"IS0": "Sardinia,EU",
"IM0": "Sardinia,EU",
"J2": "Djibouti,AF",
"J3": "Grenada,NA",
"J5": "Guinea-Bissau,AF",
"J6": "St. Lucia,NA",
"J7": "Dominica,NA",
"J8": "St. Vincent,NA",
"JA": "Japan,AS",
"JB": "Japan,AS",
"JC": "Japan,AS",
"JD": "Japan,AS",
"JE": "Japan,AS",
"JF": "Japan,AS",
"JG": "Japan,AS",
"JH": "Japan,AS",
"JI": "Japan,AS",
"JJ": "Japan,AS",
"JK": "Japan,AS",
"JL": "Japan,AS",
"JM": "Japan,AS",
"JN": "Japan,AS",
"JO": "Japan,AS",
"JP": "Japan,AS",
"JQ": "Japan,AS",
"JR": "Japan,AS",
"JS": "Japan,AS",
"7J": "Japan,AS",
"7K": "Japan,AS",
"7L": "Japan,AS",
"7M": "Japan,AS",
"7N": "Japan,AS",
"JD1": "Minami Torishima,OC",
"JD1": "Ogasawara,AS",
"JT": "Mongolia,AS",
"JU": "Mongolia,AS",
"JV": "Mongolia,AS",
"JW": "Svalbard,EU",
"JX": "Jan Mayen,EU",
"JY": "Jordan,AS",
"K": "United States of America,NA",
"W": "United States of America,NA",
"N": "United States of America,NA",
"AA": "United States of America,NA",
"AB": "United States of America,NA",
"AC": "United States of America,NA",
"AD": "United States of America,NA",
"AE": "United States of America,NA",
"AF": "United States of America,NA",
"AG": "United States of America,NA",
"AH": "United States of America,NA",
"AI": "United States of America,NA",
"AJ": "United States of America,NA",
"AK": "United States of America,NA",
"KG4": "Guantanamo Bay,NA",
"KH0": "Mariana Is.,OC",
"KH1": "Baker & Howland Is.,OC",
"KH2": "Guam,OC",
"KH3": "Johnston I.,OC",
"KH4": "Midway I.,OC",
"KH5": "Palmyra & Jarvis Is.,OC",
"KH5K": "Kingman Reef,OC",
"KH6": "Hawaii,OC",
"KH7": "Hawaii,OC",
"KH7K": "Kure I.,OC",
"KH8": "American Samoa,OC",
"KH8": "Swains I.,OC",
"KH9": "Wake I.,OC",
"KL": "Alaska,NA",
"AL": "Alaska,NA",
"NL": "Alaska,NA",
"WL": "Alaska,NA",
"KP1": "Navassa I.,NA",
"KP2": "Virgin Is.,NA",
"KP3": "Puerto Rico,NA",
"KP4": "Puerto Rico,NA",
"KP5": "Desecheo I.,NA",
"LA": "Norway,EU",
"LB": "Norway,EU",
"LC": "Norway,EU",
"LD": "Norway,EU",
"LE": "Norway,EU",
"LF": "Norway,EU",
"LG": "Norway,EU",
"LH": "Norway,EU",
"LI": "Norway,EU",
"LJ": "Norway,EU",
"LK": "Norway,EU",
"LL": "Norway,EU",
"LM": "Norway,EU",
"LN": "Norway,EU",
"LO": "Argentina,SA",
"LP": "Argentina,SA",
"LQ": "Argentina,SA",
"LR": "Argentina,SA",
"LS": "Argentina,SA",
"LT": "Argentina,SA",
"LU": "Argentina,SA",
"LV": "Argentina,SA",
"LW": "Argentina,SA",
"LX": "Luxembourg,EU",
"LY": "Lithuania,EU",
"LZ": "Bulgaria,EU",
"OA": "Peru,SA",
"OB": "Peru,SA",
"OC": "Peru,SA",
"OD": "Lebanon,AS",
"OE": "Austria,EU",
"OF": "Finland,EU",
"OG": "Finland,EU",
"OH": "Finland,EU",
"OI": "Finland,EU",
"OH0": "Aland Is.,EU",
"OJ0": "Market Reef,EU",
"OK": "Czech Republic,EU",
"OL": "Czech Republic,EU",
"OM": "Slovak Republic,EU",
"ON": "Belgium,EU",
"OO": "Belgium,EU",
"OP": "Belgium,EU",
"OQ": "Belgium,EU",
"OR": "Belgium,EU",
"OS": "Belgium,EU",
"OT": "Belgium,EU",
"OU": "Denmark,EU",
"OV": "Denmark,EU",
"OW": "Denmark,EU",
"OZ": "Denmark,EU",
"OX": "Greenland,NA",
"OY": "Faroe Is.,EU",
"P2": "Papua New Guinea,OC",
"P4": "Aruba,SA",
"P5": "DPR of Korea,AS",
"PA": "Netherlands,EU",
"PB": "Netherlands,EU",
"PC": "Netherlands,EU",
"PD": "Netherlands,EU",
"PE": "Netherlands,EU",
"PF": "Netherlands,EU",
"PG": "Netherlands,EU",
"PH": "Netherlands,EU",
"PI": "Netherlands,EU",
"PJ2": "Bonaire, Curacao,SA",
"PJ4": "Bonaire, Curacao,SA",
"PJ9": "Bonaire, Curacao,SA",
"PJ5": "St. Maarten, Saba, St.Eustatius,NA",
"PJ6": "St. Maarten, Saba, St.Eustatius,NA",
"PJ7": "St. Maarten, Saba, St.Eustatius,NA",
"PJ8": "St. Maarten, Saba, St.Eustatius,NA",
"PP": "Brazil,SA",
"PQ": "Brazil,SA",
"PR": "Brazil,SA",
"PS": "Brazil,SA",
"PT": "Brazil,SA",
"PU": "Brazil,SA",
"PV": "Brazil,SA",
"PW": "Brazil,SA",
"PX": "Brazil,SA",
"PY": "Brazil,SA",
"PP0-PY0F": "Fernando de Noronha,SA",
"PP0-PY0S": "St. Peter & St. Paul Rocks,SA",
"PP0-PY0T": "Trindade & Martim Vaz Is.,SA",
"PZ": "Suriname,SA",
"R1FJ": "Franz Josef Land,EU",
"R1MV": "Malyj Vysotskij I.,EU",
"S0": "Western Sahara,AF",
"S2": "Bangladesh,AS",
"S5": "Slovenia,EU",
"S7": "Seychelles,AF",
"S9": "Sao Tome & Principe,AF",
"SA": "Sweden,EU",
"SB": "Sweden,EU",
"SC": "Sweden,EU",
"SD": "Sweden,EU",
"SE": "Sweden,EU",
"SF": "Sweden,EU",
"SG": "Sweden,EU",
"SH": "Sweden,EU",
"SI": "Sweden,EU",
"SJ": "Sweden,EU",
"SK": "Sweden,EU",
"SL": "Sweden,EU",
"SM": "Sweden,EU",
"SN": "Poland,EU",
"SO": "Poland,EU",
"SP": "Poland,EU",
"SQ": "Poland,EU",
"SR": "Poland,EU",
"ST": "Sudan,AF",
"SU": "Egypt,AF",
"SV": "Greece,EU",
"SW": "Greece,EU",
"SX": "Greece,EU",
"SY": "Greece,EU",
"SZ": "Greece,EU",
"J4": "Greece,EU",
"SV/A": "Mount Athos,EU",
"SV5": "Dodecanese,EU",
"J45": "Dodecanese,EU",
"SV9": "Crete,EU",
"J49": "Crete,EU",
"T2": "Tuvalu,OC",
"T30": "W. Kiribati,OC",
"T31": "C. Kiribati (British Phoenix Is.),OC",
"T32": "E. Kiribati,OC",
"T33": "Banaba I.,OC",
"T5": "Somalia,AF",
"6O": "Somalia,AF",
"T7": "San Marino,EU",
"T8": "Palau,OC",
"TA": "Turkey,EU",
"TB": "Turkey,EU",
"TC": "Turkey,EU",
"TF": "Iceland,EU",
"TG": "Guatemala,NA",
"TD": "Guatemala,NA",
"TI": "Costa Rica,NA",
"TE": "Costa Rica,NA",
"TI9": "Cocos I.,NA",
"TJ": "Cameroon,AF",
"TK": "Corsica,EU",
"TL": "Central Africa,AF",
"TN": "???,AF",
"TR": "Gabon,AF",
"TT": "Chad,AF",
"TU": "Cote d Ivoire,AF",
"TY": "Benin,AF",
"TZ": "Mali,AF",
"UA": "Russia,EU",
"UB": "Russia,EU",
"UC": "Russia,EU",
"UD": "Russia,EU",
"UE": "Russia,EU",
"UF": "Russia,EU",
"UG": "Russia,EU",
"UH": "Russia,EU",
"UI": "Russia,EU",
"R": "Russia,EU",
"UA2": "Kaliningrad,EU",
"UJ": "Uzbekistan,AS",
"UK": "Uzbekistan,AS",
"UL": "Uzbekistan,AS",
"UM": "Uzbekistan,AS",
"UN": "Kazakhstan,AS",
"UO": "Kazakhstan,AS",
"UP": "Kazakhstan,AS",
"UQ": "Kazakhstan,AS",
"UR": "Ukraine,EU",
"US": "Ukraine,EU",
"UT": "Ukraine,EU",
"UU": "Ukraine,EU",
"UV": "Ukraine,EU",
"UW": "Ukraine,EU",
"UX": "Ukraine,EU",
"UY": "Ukraine,EU",
"UZ": "Ukraine,EU",
"EM": "Ukraine,EU",
"EN": "Ukraine,EU",
"EO": "Ukraine,EU",
"V2": "Antigua & Barbuda,NA",
"V3": "Belize,NA",
"V4": "St. Kitts & Nevis,NA",
"V5": "Namibia,AF",
"V6": "Micronesia,OC",
"V7": "Marshall Is.,OC",
"V8": "Brunei Darussalam,OC",
"VE": "Canada,NA",
"VO": "Canada,NA",
"VY": "Canada,NA",
"VK": "Australia,OC",
"VK0": "Heard I.,AF",
"VK0": "Macquarie I.,OC",
"VK9C": "Cocos Is.,OC",
"VK9L": "Lord Howe I.,OC",
"VK9M": "Mellish Reef,OC",
"VK9N": "Norfolk I.,OC",
"VK9W": "Willis I.,OC",
"VK9X": "Christmas I.,OC",
"VP2E": "Anguilla,NA",
"VP2M": "Montserrat,NA",
"VP2V": "British Virgin Is.,NA",
"VP5": "Turks & Caicos Is.,NA",
"VP6": "Pitcairn I.,OC",
"VP6": "Ducie I.,OC",
"VP8": "Falkland Is.,SA",
"VP8": "South Shetland Is.,SA",
"CE9": "South Shetland Is.,SA",
"HF0": "South Shetland Is.,SA",
"4K1": "South Shetland Is.,SA",
"VP9": "Bermuda,NA",
"VQ9": "Chagos Is.,AF",
"VR": "Hong Kong,AS",
"VU": "India,AS",
"VU4": "Andaman & Nicobar Is.,AS",
"VU7": "Lakshadweep Is.,AS",
"XA": "Mexico,NA",
"XB": "Mexico,NA",
"XC": "Mexico,NA",
"XD": "Mexico,NA",
"XE": "Mexico,NA",
"XF": "Mexico,NA",
"XG": "Mexico,NA",
"XH": "Mexico,NA",
"XI": "Mexico,NA",
"XA4": "Revillagigedo,NA",
"XB4": "Revillagigedo,NA",
"XC4": "Revillagigedo,NA",
"XD4": "Revillagigedo,NA",
"XE4": "Revillagigedo,NA",
"XF4": "Revillagigedo,NA",
"XG4": "Revillagigedo,NA",
"XH4": "Revillagigedo,NA",
"XI4": "Revillagigedo,NA",
"XT": "Burkina Faso,AF",
"XU": "Cambodia,AS",
"XW": "Laos,AS",
"XX9": "Macao,AS",
"XY": "Myanmar,AS",
"XZ": "Myanmar,AS",
"YA": "Afghanistan,AS",
"YB": "Indonesia,OC",
"YC": "Indonesia,OC",
"YD": "Indonesia,OC",
"YE": "Indonesia,OC",
"YF": "Indonesia,OC",
"YG": "Indonesia,OC",
"YH": "Indonesia,OC",
"YI": "Iraq,AS",
"YJ": "Vanuatu,OC",
"YK": "Syria,AS",
"YL": "Latvia,EU",
"YN": "Nicaragua,NA",
"H6": "Nicaragua,NA",
"H7": "Nicaragua,NA",
"HT": "Nicaragua,NA",
"YO": "Romania,EU",
"YP": "Romania,EU",
"YQ": "Romania,EU",
"YR": "Romania,EU",
"YS": "El Salvador,NA",
"HU": "El Salvador,NA",
"YT": "Serbia,EU",
"YU": "Serbia,EU",
"YV": "Venezuela,SA",
"YW": "Venezuela,SA",
"YX": "Venezuela,SA",
"YY": "Venezuela,SA",
"4M": "Venezuela,SA",
"YV0": "Aves I.,NA",
"Z2": "Zimbabwe,AF",
"Z3": "Macedonia,EU",
"ZA": "Albania,EU",
"ZB2": "Gibraltar,EU",
"ZC4": "UK Sov. Base Areas on Cyprus,AS",
"ZD7": "St. Helena,AF",
"ZD8": "Ascension I.,AF",
"ZD9": "Tristan da Cunha & Gough I.,AF",
"ZF": "Cayman Is.,NA",
"ZK2": "Niue,OC",
"ZK3": "Tokelau Is.,OC",
"ZL": "New Zealand,OC",
"ZM": "New Zealand,OC",
"ZL7": "Chatham Is.,OC",
"ZL8": "Kermadec Is.,OC",
"ZL9": "Auckland & Campbell Is.,OC",
"ZP": "Paraguay,SA",
"ZR": "South Africa,AF",
"ZS": "South Africa,AF",
"ZT": "South Africa,AF",
"ZU": "South Africa,AF",
"ZS8": "Prince Edward & Marion Is.,AF"
}
with open(file_name, 'w') as configfile:
config.write(configfile)
@ -751,24 +169,21 @@ class ColorSpot():
sys.exit()
return config
def get_confirmed_countries(self):
def get_confirmed_entities(self):
ret = []
#TODO: download file and/or tell user what to do
file = open("lotw.adi", "r")
file = open(self.config['files']['lotw_confirmed'], "r")
for row in file:
if re.search("COUNTRY", row):
country = row.partition(">")[2].lower().rstrip()
country = re.sub('European ', '', country, flags=re.IGNORECASE)
country = re.sub('Asiatic ', '', country, flags=re.IGNORECASE)
if country not in ret:
ret.append(country)
if re.search("<DXCC:", row):
dxcc = row.partition(">")[2].lower().rstrip()
if dxcc not in ret:
ret.append(dxcc)
return ret
@staticmethod
def check_lotw(call):
def check_lotw(self, call):
ret = ""
#TODO: download file and/or tell user what to do
csv_file = csv.reader(open('lotw-user-activity.csv', "r"), delimiter=",")
csv_file = csv.reader(open(self.config['files']['lotw_activity'], "r"), delimiter=",")
#loop through the csv file
for row in csv_file:
if call == row[0]:
@ -776,17 +191,21 @@ class ColorSpot():
return ret
return ret
@staticmethod
def get_call_details(call, data):
def get_cty_row(self, call):
done = False
while not done:
if call in data:
return data[call].split(',')
for row in self.cty:
entities = row[9].replace(";", "").replace("=", "").split(" ")
# TODO: schauen ob = davor und match -> als special call anzeigen
for prefix in entities:
if call == prefix:
return row
call = call[:-1]
if call == "":
return ["-", "-"]
return ["-", "-", "-", "-", "-", "-", "-"]
return None
def get_spots(self):
with Telnet(self.config['cluster']['host'], int(self.config['cluster']['port']), \
int(self.config['cluster']['timeout'])) as telnet:
@ -816,15 +235,20 @@ class ColorSpot():
call_dx = re.search(freq + ' +(.+?) ', line).group(1)
time = re.search('[^ ]*$', line).group(0)[0:4]
comment = re.search(call_dx + ' +(.+?) +' + time, line).group(1)
#areaname = self.get_country(call_dx, self.dxcc)
call_details = self.get_call_details(call_dx, self.config['dxcc'])
areaname = call_details[0]
continent = call_details[1]
lotw_date = self.check_lotw(call_dx)
lotw = ""
if lotw_date:
if self.check_cty:
cty_details = self.get_cty_row(call_dx)
else:
cty_details = ["-","-","-","-","-","-","-","-","-","-"]
areaname = cty_details[1]
continent = cty_details[3]
if self.check_lotw_activity and self.check_lotw(call_dx):
lotw = ""
else:
lotw = ""
try:
if self.config['colors']['color_by'] == "band":
foreground = self.config['band_colors'][freq[:-5]]
@ -837,7 +261,7 @@ class ColorSpot():
freq = freq.replace('.0', '')
if areaname.lower() not in self.qsl_countries:
if self.check_lotw_confirmed and cty_details[2] not in self.confirmed_entities:
background = self.config['colors']['alert_bg']
foreground = self.config['colors']['alert_fg']
else:
@ -858,9 +282,11 @@ class ColorSpot():
# Main Routine #
#####################################################
def main():
"""the main routine"""
color_spot = ColorSpot()
color_spot.get_spots()
try:
color_spot = ColorSpot()
color_spot.get_spots()
except KeyboardInterrupt:
sys.exit(0) # or 1, or whatever
if __name__ == "__main__":
try: