Select to view content in your preferred language

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

1422
3
09-03-2020 09:14 AM
MarkSenne
Emerging Contributor

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

0 Kudos
3 Replies
DanPatterson
MVP Esteemed Contributor

Mark Senne‌ could you format your code to provide proper indentation and line numbers

/blogs/dan_patterson/2016/08/14/script-formatting 


... sort of retired...
MarkSenne
Emerging Contributor

Dan, I have updated the original question with the actual Python script as an attachment

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Well, for starters Line #18, arcpu ?

Of the attached script, what line exactly is giving the error and what is the error and traceback?