forked from SpaceApi/directory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate.py
executable file
·37 lines (31 loc) · 938 Bytes
/
validate.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
#!/usr/bin/env python2
import requests
import json
import collections
# Get spaces list
directory_file = './directory.json'
directory = open(directory_file, 'r')
spaces = json.loads(directory.read())
spaces_new = {}
# Check spaces
for key in spaces:
url = spaces[key]
if 'spaceapi.net' in url:
continue
try:
print '%s %s' % (key, url)
req = requests.get(url, verify=False, timeout=10)
if req.status_code == 200:
spaces_new[key] = url
else:
print '\t\033[0;31m\\_ Status: %s: %s\033[0m' \
% (req.status_code, req.reason)
except Exception,e:
print '\t\033[0;31m\\_Error: %s\033[0m' % (e)
directory.close()
# Save new spaces
directory = open(directory_file, 'w+')
json_str = json.dumps(spaces_new, indent=2, sort_keys=True, separators=(',', ':'))
json_str = json_str.replace('/', '\\/')
directory.write(json_str)
directory.close()