-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpopulate.py
More file actions
executable file
·31 lines (23 loc) · 895 Bytes
/
populate.py
File metadata and controls
executable file
·31 lines (23 loc) · 895 Bytes
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
#!/usr/bin/env python
import argparse, requests
parser = argparse.ArgumentParser(description='Submit trending POST requests with Chartbeat toppages data.')
parser.add_argument('hosts', metavar='DOMAIN NAME', type=str, nargs='+', help='hosts to gather (e.g., "gizmodo.com")')
args = parser.parse_args()
for host in args.hosts:
print 'Retrieving {host}...'.format(host=host)
params = {
'apikey': '317a25eccba186e0f6b558f45214c0e7',
'host': host,
'limit': '100',
}
r = requests.get('http://api.chartbeat.com/live/toppages', params=params)
data = {
'host': host,
'pages': r.text
}
r2 = requests.post('http://127.0.0.1:5000/api/1/trending', data=data)
info = r2.json()
if info['status'] == 200:
print 'Successfully posted {host} to local server.'.format(host=host)
else:
print 'Failed to post {host} to local server ({error}).'.format(host=host, error=info['error'])