ttt
This commit is contained in:
parent
34ae0d90da
commit
33f43d2e3b
109
exif.py
109
exif.py
@ -124,20 +124,70 @@ def files(path):
|
||||
for file in os.listdir(path):
|
||||
if os.path.isfile(os.path.join(path, file)):
|
||||
yield file
|
||||
folder = "./data/"
|
||||
|
||||
filenames = os.listdir(folder)
|
||||
|
||||
targetfolder = "./data/"
|
||||
|
||||
|
||||
|
||||
def photoupload(targetfolder):
|
||||
filenames = os.listdir(targetfolder)
|
||||
testfiles = [ x for x in filenames if os.path.isfile(os.path.join(targetfolder,x)) == True ]
|
||||
|
||||
testdirs = [ x for x in filenames if os.path.isdir(os.path.join(targetfolder,x)) == True ]
|
||||
for testdir in testdirs:
|
||||
photoupload(testdir)
|
||||
|
||||
for filename in testfiles:
|
||||
# newfilename = filename.encode('utf-8')
|
||||
targetname,targetext = os.path.splitext(filename)
|
||||
pathfile = folder+filename
|
||||
f2 = "./done/"+filename
|
||||
f = open(pathfile,'rb')
|
||||
if targetext == ".mp4":
|
||||
print (".mp4")
|
||||
# print_all_metadata_atoms(Mp4File(pathfile))
|
||||
# exit()
|
||||
else:
|
||||
tags = exifread.process_file(f, stop_tag=exif_choice)
|
||||
# print (pathfile)
|
||||
for tag in tags.keys():
|
||||
if tag in (exif_choice):
|
||||
photodatetime=tags[tag]
|
||||
T=datetime.datetime.strptime(str(photodatetime)[0:10],'%Y:%m:%d')
|
||||
day=T.strftime('%d')
|
||||
if(int(day)<=7):
|
||||
fromto=T.strftime('%Y%m01_%Y%m07')
|
||||
elif (int(day)<=14):
|
||||
fromto=T.strftime('%Y%m08_%Y%m14')
|
||||
elif (int(day)<=21):
|
||||
fromto=T.strftime('%Y%m15_%Y%m21')
|
||||
else:
|
||||
year=int(T.strftime('%Y'))
|
||||
month=int(T.strftime('%m'))
|
||||
lastday=monthrange(year,month)[1]
|
||||
#print(lastday)
|
||||
fromto=T.strftime('%Y%m22_%Y%m'+str(lastday))
|
||||
print(T.strftime('%Y'),T.strftime('%m'),fromto)
|
||||
parentid=getidbyname3(T.strftime('%Y'),T.strftime('%m'),fromto)
|
||||
try:
|
||||
print("Try:",pathfile)
|
||||
mySite.pwg.images.addSimple(image=pathfile, category=parentid)
|
||||
print("Success:",pathfile)
|
||||
os.rename(pathfile,f2)
|
||||
#delete
|
||||
except Exception as e:
|
||||
print(e)
|
||||
pass
|
||||
#print (T)
|
||||
#print ("Key: %s, value %s" % (tag, tags[tag]))
|
||||
|
||||
photoupload(targetfolder)
|
||||
|
||||
|
||||
|
||||
|
||||
testfiles = [ x for x in filenames if os.path.isfile(os.path.join(folder,x)) == True ]
|
||||
|
||||
testdirs = [ x for x in filenames if os.path.isfile(os.path.join(folder,x)) == True ]
|
||||
|
||||
for filename in testdirs:
|
||||
print (filename)
|
||||
|
||||
#print (testfiles)
|
||||
|
||||
#exit()
|
||||
@ -153,46 +203,3 @@ for filename in testdirs:
|
||||
|
||||
|
||||
#for filename in filenames:
|
||||
for filename in testfiles:
|
||||
# newfilename = filename.encode('utf-8')
|
||||
targetname,targetext = os.path.splitext(filename)
|
||||
pathfile = folder+filename
|
||||
f2 = "./done/"+filename
|
||||
f = open(pathfile,'rb')
|
||||
if targetext == ".mp4":
|
||||
print (".mp4")
|
||||
# print_all_metadata_atoms(Mp4File(pathfile))
|
||||
# exit()
|
||||
else:
|
||||
tags = exifread.process_file(f, stop_tag=exif_choice)
|
||||
# print (pathfile)
|
||||
for tag in tags.keys():
|
||||
if tag in (exif_choice):
|
||||
photodatetime=tags[tag]
|
||||
T=datetime.datetime.strptime(str(photodatetime)[0:10],'%Y:%m:%d')
|
||||
day=T.strftime('%d')
|
||||
if(int(day)<=7):
|
||||
fromto=T.strftime('%Y%m01_%Y%m07')
|
||||
elif (int(day)<=14):
|
||||
fromto=T.strftime('%Y%m08_%Y%m14')
|
||||
elif (int(day)<=21):
|
||||
fromto=T.strftime('%Y%m15_%Y%m21')
|
||||
else:
|
||||
year=int(T.strftime('%Y'))
|
||||
month=int(T.strftime('%m'))
|
||||
lastday=monthrange(year,month)[1]
|
||||
#print(lastday)
|
||||
fromto=T.strftime('%Y%m22_%Y%m'+str(lastday))
|
||||
print(T.strftime('%Y'),T.strftime('%m'),fromto)
|
||||
parentid=getidbyname3(T.strftime('%Y'),T.strftime('%m'),fromto)
|
||||
try:
|
||||
print("Try:",pathfile)
|
||||
mySite.pwg.images.addSimple(image=pathfile, category=parentid)
|
||||
print("Success:",pathfile)
|
||||
os.rename(pathfile,f2)
|
||||
#delete
|
||||
except Exception as e:
|
||||
print(e)
|
||||
pass
|
||||
#print (T)
|
||||
#print ("Key: %s, value %s" % (tag, tags[tag]))
|
||||
|
Loading…
x
Reference in New Issue
Block a user