-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetRidOfTokens.py
58 lines (46 loc) · 1.55 KB
/
getRidOfTokens.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
55
56
57
58
import requests
from collections import namedtuple
import logging
from credentials import get_credentials
log = logging.getLogger("global")
console = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s %(levelname)s : %(message)s')
console.setFormatter(formatter)
log.addHandler(console)
log.setLevel(logging.INFO)
log.debug("Starting")
#config
auth_credentials = get_credentials()
mapDocumentTypeId = 1
pdfDocumentTypeId = 13
maxDocsToProcess = 999000
onlyProcessEmptyDocType = True
# Scan through tokens and art and delete everything past the first 2500 docs
docs = 0
pageUrl = "http://jittikun:8000/api/documents/?document_type__id__in=14&sort=created&reverse=1"
docsToDelete = []
response = requests.get(pageUrl, auth = auth_credentials)
rawJson = response.json()
log.debug(rawJson)
docsToProcess = len(rawJson["all"])
log.debug(f"Processing {docsToProcess} documents")
for docId in rawJson["all"]:
log.debug(f"process docId {docId}")
if docs > 2500:
docsToDelete.append(docId)
#end if
docs += 1
if docs == maxDocsToProcess:
break
#end for
body = {
"documents": docsToDelete,
"method": "delete",
"parameters": {
}
}
log.debug(f"Bulk deleting {len(docsToDelete)} documents. Documents: {docsToDelete}")
editResponse = requests.post("http://jittikun:8000/api/documents/bulk_edit/", auth = auth_credentials, json = body)
log.debug(editResponse)
if editResponse.status_code != 200:
log.error(f"Failed to bulk delete pages. Full response is {editResponse}")