-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetRekognitionFiles.py
More file actions
executable file
·144 lines (108 loc) · 4.64 KB
/
Copy pathgetRekognitionFiles.py
File metadata and controls
executable file
·144 lines (108 loc) · 4.64 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
from queryAlf import runQuery
import pandas as pd, json
import os
from dotenv import load_dotenv
import requests,json
from requests.auth import HTTPBasicAuth
#test nodeid in rwilds232: 19264eec-0d3e-4afe-80df-acc72c4e950b
# Load environment variables from the .env file
load_dotenv()
BASE_URL= os.getenv("BASE_URL")
auth = os.getenv("auth")
user = os.getenv("user")
passwd = os.getenv("pass")
devpath = os.getenv("devpath")
prodpath = os.getenv("prodpath")
path = prodpath # set the working path here once!
rekogSrc= []
rekogName= []
rekogLabels = []
rekogParent = []
rekogNodeId = []
rekogModifiedDate = []
cols = {0: 'src',1:'name',2:'labels',3:'parentId',4:'nodeId',5:'modifiedDate'}
def downloadImages(nodeid,path):
url = BASE_URL + "/alfresco/api/-default-/public/alfresco/versions/1/nodes/"+nodeid+"/content"
temp4 = requests.get(url,auth = (user, passwd))
#print(temp4.text)
#put process here to determine extension based on mimetype
#could use this: https://note.nkmk.me/en/python-mimetypes-usage/
#check if file is already there, otherwise skip it
#this could be bad if an existing node gets a new file
filePath = path + nodeid+".jpg"
fileName = nodeid+".jpg"
if os.path.exists(filePath):
print('file already exists-> '+filePath+'\n')
else:
print('file doesn''t exist-> '+filePath+'\n')
with open(filePath,'wb') as f:
f.write(temp4.content)
return fileName
def cleanFolder(path):
for i in os.listdir(path):
if ".json" not in i:
print("removing file: "+i)
os.remove(path+i)
def pullListofrekogfiles():
imageQuery = BASE_URL + '/alfresco/api/-default-/public/search/versions/1/search'
postData = """{
"query": {
"query": "ASPECT:'ai:labels'"
}
}"""
data=runQuery('post',imageQuery,postData,user,passwd)
#print ('query url is: ' + imageQuery + '--->>>>' + postData) #debug
return data
def getrekogfilesinfo(nodeid):
nodeInfoQuery = BASE_URL + '/alfresco/api/-default-/public/alfresco/versions/1/nodes/' + nodeid +'?fields=properties,name,id,modifiedAt' #use fileIds to limit the amount of data returned
data=runQuery('get',nodeInfoQuery,'',user,passwd)
print ('\n\ndata from alfresco -->' + json.dumps(data)) #debugging
return data;
def createPath(path):
if not os.path.exists(path):
os.makedirs(path)
print(path + ' Created')
def getTagValue(tagidArray):
#loop through each entry to get the name and add to array then return array
tagvalArray = []
for entry in tagidArray:
tagvaluequery = BASE_URL + '/alfresco/api/-default-/public/alfresco/versions/1/tags/'+entry
data = runQuery('get',tagvaluequery,'',user,passwd)
tagvalArray.append(data['entry']['tag'])
print ('\n data from Tag routine -> '+str(tagvalArray))
return tagvalArray
def main(requestURL="Http://localllll/"): #the hardcode url is in place for running from command line not from flask
#clear arrays now!
rekogSrc = []
rekogLabels = []
rekogName = []
rekogParent = []
rekogNodeId = []
rekogModifiedDate = []
runOnce = False
#create the storage path for the downloaded files
createPath(path)
#clean the download folder now!
#cleanFolder(path)
#print('search result --> ' + json.dumps(pullListofrekogfiles())) #debug
#now loop and get all images to download and populate data frame columns
for entry in pullListofrekogfiles()['list']['entries']:
#print('node-> ' + entry['entry']['id'] + ' labels-> ' + str(getrekogfilesinfo(entry['entry']['id'])['entry']['properties']['schema:label'])) #debugging
rekogSrc.append(requestURL+'static/' + downloadImages(entry['entry']['id'],path))
rekogName.append(entry['entry']['name'])
#rekogLabels.append(getrekogfilesinfo(entry['entry']['id'])['entry']['properties']['schema:label'])
rekogLabels.append(getTagValue(getrekogfilesinfo(entry['entry']['id'])['entry']['properties']['cm:taggable']))
#print('Tag value from caller -> ' + getTagValue(getrekogfilesinfo(entry['entry']['id'])['entry']['properties']['cm:taggable']))
#added to identify hyland employees
#print ('\\n\\n debug for schema:textLines -> '+ str(getrekogfilesinfo(entry['entry']['id'])['entry']['properties']['cm:taggable']))
#rekogLabels.append(getrekogfilesinfo(entry['entry']['id'])['entry']['properties']['schema:textLines'])
rekogParent.append(entry['entry']['parentId'])
rekogNodeId.append(entry['entry']['id'])
rekogModifiedDate.append(entry['entry']['modifiedAt'])
rekogDF = pd.DataFrame([rekogSrc,rekogName,rekogLabels,rekogParent,rekogNodeId,rekogModifiedDate]).T
rekogDF.rename(columns=cols,inplace=True)
print (rekogDF)
#rekogDF.to_excel('rekogfiles.xlsx')
return rekogDF
if __name__ == "__main__":
main()