forked from public-apis/public-apis
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtable_reorder.py
89 lines (79 loc) · 2.06 KB
/
table_reorder.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
86
87
88
89
import pandas as pd
import requests
def try_connect(url):
try:
response = requests.get(url, )
return "Yes" if response.status_code == 200 else "No"
except Exception as e:
print(e)
return "Unknown"
if __name__ == '__main__':
ls = """Animals
Anime
Anti-Malware
Art & Design
Authentication & Authorization
Blockchain
Books
Business
Calendar
Cloud Storage & File Sharing
Continuous Integration
Cryptocurrency
Currency Exchange
Data Validation
Development
Dictionaries
Documents & Productivity
Email
Entertainment
Environment
Events
Finance
Food & Drink
Games & Comics
Geocoding
Government
Health
Jobs
Machine Learning
Music
News
Open Data
Open Source Projects
Patent
Personality
Phone
Photography
Programming
Science & Math
Security
Shopping
Social
Sports & Fitness
Test Data
Text Analysis
Tracking
Transportation
URL Shorteners
Vehicle
Video
Weather""".split("\n")
tables = pd.read_html("https://github.com/public-apis/public-apis")
tables_with_links = pd.read_html("https://github.com/public-apis/public-apis", extract_links="body")
output = ""
for inum, v in enumerate(tables[2:]):
k = ls[inum]
output += f"### {k}\n"
v["API"] = tables_with_links[inum+2]["API"].apply(lambda x:f"[{x[0]}]({x[1]})")
v["Available"] = tables_with_links[inum + 2]["API"].apply(lambda x: try_connect(x[1]))
tables[2+inum] = v
for inum, v in enumerate(tables[2:]):
v["cn_Available"] = tables_with_links[inum + 2]["API"].apply(lambda x: try_connect(x[1]))
v = v.sort_values(by=["cn_Available", "Available", "Auth", "HTTPS", "CORS", "API"], ascending=[False, True, False, False, True])
v = v.reset_index(drop=True)
v.index += 1
# v["available"] = "Unknown"
output += f"{v.to_markdown()}\n\n"
output += """**[⬆ Back to Index](#index)**\n<br >\n<br >\n\n"""
print()