-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvp-fetch.py
85 lines (60 loc) · 1.94 KB
/
vp-fetch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#import required library
from bullet import Bullet
import pandas as pd
import requests
import io
import base64
# request header
headers = {
"User-Agent": "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html"
}
def decode_data(coded_string):
"""return the base64 decoded string"""
return base64.b64decode(coded_string)
def write_to_file(name, coded_string):
"""write the data to the .ovpn file"""
name = f"{name}.ovpn"
with open(name, "wb") as fd:
fd.write(coded_string)
print(f"\nThe file is saved with the name => {name}")
if __name__ == "__main__":
# fetching data
try:
csv_content = requests.get(
"http://www.vpngate.net/api/iphone/", headers=headers, timeout=10
).content
except requests.exceptions.ConnectionError:
print("Unable to fetch data !!")
print("Try again !!")
exit(0)
# reading the csv data
data = pd.read_csv(io.BytesIO(csv_content), skiprows=1)
#remove the nan
data = data.loc[data['CountryLong'].notna()]
# Available coutries
country_list = list(set(data["CountryLong"]))
select_country = Bullet(
prompt = "\nPlease choose the country: ",
choices = country_list,
indent = 0,
align = 5,
margin = 2,
shift = 0,
bullet = "",
pad_right = 5,
return_index = True
)
result = select_country.launch()
print("You chose country:", result[0])
selected = data[data["CountryLong"] == result[0]]
if not selected.empty:
# sort according to the Score
selected = selected.sort_values("Score")
# select the first entry with the best score
base_code = selected.iloc[0, -1]
# decode base code
base_code = decode_data(base_code)
# write the *.ovpn file in current dir
write_to_file(result[0], base_code)
else:
print("Incorrect country name !!")