-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpullstats.py
54 lines (42 loc) · 1.58 KB
/
pullstats.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
import urllib.request
import json
import boto3
dynamodb = boto3.resource('dynamodb', region_name='us-west-2')
table = dynamodb.Table('relaylist')
response = table.scan()
data = response['Items']
# print(data)
hdr = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}
for relay in data:
try:
data = json.load(urllib.request.urlopen(
urllib.request.Request(relay['url'], headers=hdr)))
except:
print('Issue with site')
try:
if data['version'] == '2.0':
output = relay['name'] + " (Open: " + str(data['openRegistrations']) + \
"): " + str(len(data['metadata']['peers']))
table.put_item(
Item={
'name': relay['name'],
'url' : relay['url'],
'open': bool(data['openRegistrations']),
'server_count': str(len(data['metadata']['peers'])),
}
)
elif data['version'] == '2.1':
output = relay['name'] + " (Open: " + str(data['openRegistrations']) + "): " + \
str(data['usage']['users']['activeMonth'])
table.put_item(
Item={
'name': relay['name'],
'url' : relay['url'],
'open': bool(data['openRegistrations']),
'server_count': str(len(data['metadata']['peers'])),
}
)
print(output)
except:
print('Issue with data')