AnsweredAssumed Answered

Need help with invalid syntax in Python with picture to blob script

Question asked by msenne on Sep 3, 2020
Latest reply on Sep 3, 2020 by bixb0012

Hey everyone,

I am trying to edit an older script where pictures are placed in a folder from a collector map with picture attachments, it's been about a year since we have had to run this script and we are running into an error that says "Invalid syntax" on our arcpy.da.searchcursor function. This parcticular script is also supposed to place watermarks on our photos but we can't get it to work.

Here is the full code:

 

#Import the needed modules
import arcpy,os,sys

#Directory where files will be saved
#********Change to desired location and leave off the last backslash***********
saveDir = r'X:\TVA\NorthDeSoto\Deliverables\PicsWatermarked'

#Specify Table & FC
featureTable = r'X:\TVA\NorthDeSoto\Features\TVA_NorthDeSotoPoints20200902.gdb\Points__ATTACH'
featureClass = r'X:\TVA\NorthDeSoto\Features\TVA_NorthDeSotoPoints20200902.gdb\Points'


count=0
#Loop through rows
with arcpy.da.SearchCursor(featureTable,["REL_GLOBALID","DATA","ATT_NAME"]) as cursor:
for row in cursor:
flag=0
fileCount=2
wellName=""
#Replace second field with the field you want the files named (to LocID)
with arcpy.da.SearchCursor(featureClass,["GlobalID","FeatureID"]) as cursor2:
for row2 in cursor2:
if row2[0]==row[0]:
wellName = str(row2[1])

finalName = ""
if wellName==None or wellName=="":
##################################
###################################
###Change to zero if you want all pictures
###################################
###################################
flag=0
if wellName !=None:
wellName = wellName.replace("/","_").replace(".0","")
if os.path.exists(os.path.join(saveDir,wellName+'.jpg')):
while os.path.exists(os.path.join(saveDir,wellName+'.jpg')):
if os.path.exists(os.path.join(saveDir,wellName+'_'+str(fileCount)+'.jpg')):
fileCount = fileCount+1
else:
finalName = wellName+'_'+str(fileCount)
break
else:
finalName=wellName

if flag==0:
#Replace first field with the word you want in front of photo name
image = open(os.path.join(saveDir,"Pic_"+finalName+"_"+row[2].replace('.jpg','')+'.jpg'),'wb')
print finalName
image.write(row[1].tobytes())
image.close()
del image
count=count+1
print count
del wellName,finalName
#sys.exit()

 


#SDG

 

 

I have also attached a jpg of where the error occurs

Outcomes