-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtransfer_all_user_requests.py
More file actions
executable file
·40 lines (31 loc) · 1.14 KB
/
transfer_all_user_requests.py
File metadata and controls
executable file
·40 lines (31 loc) · 1.14 KB
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
#!/usr/bin/env python2
# -- coding: utf-8 --
import requests as http_request
import json
import utils
url = utils.API_URL
token = utils.get_api_key()
headers = utils.get_headers(token)
username = raw_input('Which user do you want to remove requests from?: ')
destination = raw_input('Destination user ID (not username): ')
next_url = url + "foia/?user=" + username
current_page = 0
while next_url:
# we use next_url because the API results are paginated
r = http_request.get(next_url, headers=headers)
data = r.json()
next_url = data['next']
# measures progress by page, not by result
current_page += 1
total_pages = (data['count'] / 20.0)
utils.display_progress(current_page, total_pages)
for request in data['results']:
print "Working on request " + str(request['id'])
request_id = request['id']
request_url = 'https://www.muckrock.com/api_v1/foia/%s/' % str(request_id)
print "This is the request url " + request_url
data = json.dumps({
'user': destination
})
print data
editedRequest = http_request.patch(request_url, headers=headers, data=data)