Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_data_from_api(
country_code: str, area: str, p2p: bool, dedicated: bool, double_vpn: bool,
tor_over_vpn: bool, anti_ddos: bool, netflix: bool, location: float) -> List:
url = "https://api.nordvpn.com/server"
json_response = get_json(url)
type_filtered_servers = filters.filter_by_type(
json_response, p2p, dedicated, double_vpn, tor_over_vpn, anti_ddos, netflix)
if location:
type_location_filtered = filters.filter_by_location(location, type_filtered_servers)
return type_location_filtered
if country_code != "all": # if "-l" had country code with it. e.g "-l au"
type_country_filtered = filters.filter_by_country(country_code, type_filtered_servers)
if area is None:
return type_country_filtered
type_country_area_filtered = filters.filter_by_area(area, type_country_filtered)
return type_country_area_filtered
return type_filtered_servers
def find_better_servers(country_code: str, area: str, max_load: int, top_servers: int, tcp: bool,
p2p: bool, dedicated: bool, double_vpn: bool, tor_over_vpn: bool,
anti_ddos: bool, netflix: bool, location: float, stats: bool) -> List:
if tcp:
used_protocol = "OPENVPN-TCP"
else:
used_protocol = "OPENVPN-UDP"
# use api.nordvpn.com
json_res_list = api.get_data_from_api(
country_code=country_code, area=area, p2p=p2p, dedicated=dedicated,
double_vpn=double_vpn, tor_over_vpn=tor_over_vpn, anti_ddos=anti_ddos,
netflix=netflix, location=location)
server_list = filters.filter_by_protocol(json_res_list=json_res_list, tcp=tcp)
better_servers_list = filters.filter_by_load(server_list, max_load, top_servers)
if stats:
print(Style.BRIGHT + Fore.BLUE + "According to NordVPN, \
Least Busy " + Fore.GREEN + str(len(better_servers_list)) + Fore.BLUE + " Servers in \
" + Fore.GREEN + country_code.upper() + Fore.BLUE, end=" ")
if area:
print("in Location" + Fore.GREEN, json_res_list[0]["location_names"], end=" ")
print(Fore.BLUE + "With 'Load' Less Than", Fore.GREEN + str(max_load) + Fore.BLUE,
"Which Support", Fore.GREEN + used_protocol, end=" ")
if p2p:
print(", p2p =", p2p, end=" ")
if dedicated:
print(", dedicated =", dedicated, end=" ")
def get_data_from_api(
country_code: str, area: str, p2p: bool, dedicated: bool, double_vpn: bool,
tor_over_vpn: bool, anti_ddos: bool, netflix: bool, location: float) -> List:
url = "https://api.nordvpn.com/server"
json_response = get_json(url)
type_filtered_servers = filters.filter_by_type(
json_response, p2p, dedicated, double_vpn, tor_over_vpn, anti_ddos, netflix)
if location:
type_location_filtered = filters.filter_by_location(location, type_filtered_servers)
return type_location_filtered
if country_code != "all": # if "-l" had country code with it. e.g "-l au"
type_country_filtered = filters.filter_by_country(country_code, type_filtered_servers)
if area is None:
return type_country_filtered
type_country_area_filtered = filters.filter_by_area(area, type_country_filtered)
return type_country_area_filtered
return type_filtered_servers