-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathclean_remote_resources.py
More file actions
37 lines (27 loc) · 1.39 KB
/
clean_remote_resources.py
File metadata and controls
37 lines (27 loc) · 1.39 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
import requests
from txclib.parsers import status_parser
from txclib.project import Project
from txclib.utils import find_dot_tx
project_slug = 'documentation-5'
organization_slug = 'opendatasoft'
prj = Project(find_dot_tx())
api_auth = prj.getset_host_credentials('https://api.transifex.com')
offset = 0
remote_resources = []
while True:
r = requests.get('https://api.transifex.com/organizations/{}/projects/{}/resources/?offset={}'.format(organization_slug, project_slug, offset), auth=api_auth)
results = r.json()
if len(results) == 0:
break
remote_resources.extend(results)
offset += 100
remote_resources_set = set([res['slug'] for res in remote_resources])
local_resources_set = set([res.split('.')[1] for res in prj.get_chosen_resources([])])
print "remote resources count: {}".format(len(remote_resources_set))
print "local resources count: {}".format(len(local_resources_set))
outdated_resources = remote_resources_set - local_resources_set
for res_slug in outdated_resources:
print "deleting outdated resource {}".format(res_slug)
# it seems delete is currently not working on the new api
# r = requests.delete('https://api.transifex.com/organizations/{}/projects/{}/resources/{}/'.format(organization_slug, project_slug, res_slug), auth=api_auth)
r = requests.delete('https://www.transifex.com/api/2/project/{}/resource/{}/'.format(project_slug, res_slug), auth=api_auth)