def run(): page = requests.get('https://www.qrz.com/dxcluster', verify=False).content soup = BeautifulSoup(page, 'html.parser') table = soup.find_all('table')[1] rows = table.find_all('tr') for row in rows[1:]: notifications.append(CallSignObj(row.find_all('td'))) [notifications.remove(n) for n in notifications if n.frequency > 60] recent_contacts = [ n for n in [ n for n in notifications if (datetime.now() - n.time).total_seconds() / 60 < 5 ] if bool(n.dx) ] your_qth = """longitude, latitude""" for a in recent_contacts: try: page = requests.get('http://api.hamdb.org/v1/' + a.stateside + '/xml').content.decode() root = ElementTree.fromstring(page) stateside_coordinates = root[0][4].text, root[0][5].text d = round(distance(your_qth, stateside_coordinates).miles, 1) a.__setattr__('distance_miles', d) time.sleep(4) except Exception as e: print('ERROR qsl_clusters line 47', e, type(e), a.stateside) recent_contacts.remove(a) close_contacts = [n for n in recent_contacts if n.distance_miles < 500] for c in close_contacts: dx_country = '' try: page = requests.get('http://api.hamdb.org/v1/' + c.dx + '/xml').content.decode() root = ElementTree.fromstring(page) dx_country = root[0][15].text if dx_country == 'NOT_FOUND': page = requests.get('https://www.qrz.com/lookup/' + c.dx, verify=False).content.decode() soup = BeautifulSoup(page, 'html.parser') dx_country = soup.find(id='flg')['alt'].replace(' flag', '') else: dx_country = root[0][15].text time.sleep(2) except ValueError: print('2https://www.qrz.com/lookup/' + c.dx) page = requests.get('https://www.qrz.com/lookup/' + c.dx, verify=False).content.decode() soup = BeautifulSoup(page, 'html.parser') dx_country = soup.find(id='flg')['alt'].replace(' flag', '') except Exception as e: print('ERROR qsl_clusters line 64', e, c.dx, root) time.sleep(2) close_contacts.remove(c) c.__setattr__( 'dx_country', dx_country.replace('&', 'and').replace(' Island', '').replace( 'St ', 'Saint ').rstrip().lstrip()) try: country = CountryInfo(c.dx_country) c.__setattr__('subregion', country.subregion()) except: pass return close_contacts
category_index = categories.index(category) print("Q" + str(i + 1) + ". What is the " + category + " of " + countries_question[i] + "?") country = CountryInfo(countries_question[i]) country_pool = countries country_pool = [x for x in country_pool if x != countries_question[i]] country_pool = rand.sample(country_pool, options[category_index] - 1) country_pool.append(countries_question[i]) rand.shuffle(country_pool) if category == "subregion": subregion_pool = subregions subregion_pool = [ y for y in subregion_pool if y != country.subregion() ] subregion_pool = rand.sample(subregion_pool, options[category_index] - 1) subregion_pool.append(country.subregion()) rand.shuffle(subregion_pool) index = subregion_pool.index(country.subregion()) elif category == "currency": currencies_pool = currencies currencies_pool = [ y for y in currencies_pool if y != country.currencies()[0] ] currencies_pool = rand.sample(currencies_pool, options[category_index] - 1) currencies_pool.append(country.currencies()[0])
print(f'\n\nCountry Area:\n{country_area}') country_borders = country.borders() print('\nBorders:') for border in country_borders: print(border, end=', ') calling_codes = country.calling_codes() print('\n\nCall Code:') for call_code in calling_codes: print(call_code) country_region = country.region() print(f'\nRegion:\n{country_region}') sub_region = country.subregion() print(f'\nSub-Region:\n{sub_region}') country_population = country.population() print(f'\nPopulation:\n{country_population}') country_states = country.provinces() print('\nStates/Provinces:') for states in country_states: print(states, end=', ') about_country = country.wiki() country_map = country.capital_latlng() map = folium.Map(location=(country_map)) print(