first
This commit is contained in:
commit
68090ce2b8
79
PiwigoUpload.py
Normal file
79
PiwigoUpload.py
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
import os
|
||||||
|
import random
|
||||||
|
from piwigo import *
|
||||||
|
import urllib.request as urllib2
|
||||||
|
import urllib.parse as urlparse
|
||||||
|
import math
|
||||||
|
def download_file(url, dest=None, destname=None):
|
||||||
|
"""
|
||||||
|
Download and save a file specified by url to dest directory,
|
||||||
|
"""
|
||||||
|
u = urllib2.urlopen(url)
|
||||||
|
|
||||||
|
scheme, netloc, path, query, fragment = urlparse.urlsplit(url)
|
||||||
|
if destname == None:
|
||||||
|
filename = os.path.basename(path)
|
||||||
|
else:
|
||||||
|
filename = destname
|
||||||
|
if not filename:
|
||||||
|
filename = 'downloaded.file'
|
||||||
|
if dest:
|
||||||
|
filename = os.path.join(dest, filename)
|
||||||
|
if os.path.exists(filename):
|
||||||
|
print("FileExist");
|
||||||
|
return;#raise NameError('duplicat')
|
||||||
|
with open(filename, 'wb') as f:
|
||||||
|
meta = u.info()
|
||||||
|
meta_func = meta.getheaders if hasattr(meta, 'getheaders') else meta.get_all
|
||||||
|
meta_length = meta_func("Content-Length")
|
||||||
|
file_size = None
|
||||||
|
if meta_length:
|
||||||
|
file_size = int(meta_length[0])
|
||||||
|
print("Downloading: {0} filename {1} Bytes: {2}".format(url, filename, file_size))
|
||||||
|
|
||||||
|
file_size_dl = 0
|
||||||
|
block_sz = 8192
|
||||||
|
while True:
|
||||||
|
buffer = u.read(block_sz)
|
||||||
|
if not buffer:
|
||||||
|
break
|
||||||
|
|
||||||
|
file_size_dl += len(buffer)
|
||||||
|
f.write(buffer)
|
||||||
|
|
||||||
|
status = "{0:16}".format(file_size_dl)
|
||||||
|
if file_size:
|
||||||
|
status += " [{0:6.2f}%]".format(file_size_dl * 100 / file_size)
|
||||||
|
status += chr(13)
|
||||||
|
print(status, end="")
|
||||||
|
print()
|
||||||
|
|
||||||
|
return filename
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
mySite = Piwigo('https://pho.flywithu.com/')
|
||||||
|
mySite.pwg.session.login(username="flywithu", password="1q2w3e4r5t")
|
||||||
|
#categories=mySite.pwg.categories.getList(recursive="true")['categories']
|
||||||
|
|
||||||
|
#for cat in categories:
|
||||||
|
#print(cat)
|
||||||
|
|
||||||
|
imagesinfo=mySite.pwg.categories.getImages(recursive="true")['paging']
|
||||||
|
#print(imagesinfo['count'])
|
||||||
|
total=imagesinfo['count']
|
||||||
|
perpage = 300
|
||||||
|
pagecount = math.ceil(int(total)/perpage)
|
||||||
|
|
||||||
|
print ("pagecount :",pagecount)
|
||||||
|
for x in range(pagecount):
|
||||||
|
print("pagecount:",x)
|
||||||
|
images=mySite.pwg.categories.getImages(recursive="true",per_page=perpage,page=x)['images']
|
||||||
|
for image in images:
|
||||||
|
print(image['element_url'])
|
||||||
|
download_file(image['element_url'],"data",image['file'])
|
||||||
|
mySite.pwg.session.logout()
|
||||||
|
|
||||||
|
|
||||||
|
|
96
PiwigoUpload2.py
Normal file
96
PiwigoUpload2.py
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
import os
|
||||||
|
import random
|
||||||
|
from piwigo import *
|
||||||
|
import urllib.request as urllib2
|
||||||
|
import urllib.parse as urlparse
|
||||||
|
import math
|
||||||
|
import filecmp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def download_file(url, dest=None, destname=None):
|
||||||
|
"""
|
||||||
|
Download and save a file specified by url to dest directory,
|
||||||
|
"""
|
||||||
|
u = urllib2.urlopen(url)
|
||||||
|
isDuplicate = False
|
||||||
|
scheme, netloc, path, query, fragment = urlparse.urlsplit(url)
|
||||||
|
f1=""
|
||||||
|
if destname == None:
|
||||||
|
filename = os.path.basename(path)
|
||||||
|
else:
|
||||||
|
filename = destname
|
||||||
|
if not filename:
|
||||||
|
filename = 'downloaded.file'
|
||||||
|
if dest:
|
||||||
|
filename = os.path.join(dest, filename)
|
||||||
|
if os.path.exists(filename):
|
||||||
|
print("FileExist");
|
||||||
|
isDuplicate = True
|
||||||
|
f1=filename
|
||||||
|
tempf1 = os.path.splitext(os.path.basename(f1))[0]
|
||||||
|
filename=os.path.join(dest,"dup",tempf1+"_"+os.path.basename(path))
|
||||||
|
#return;#raise NameError('duplicat')
|
||||||
|
with open(filename, 'wb') as f:
|
||||||
|
meta = u.info()
|
||||||
|
meta_func = meta.getheaders if hasattr(meta, 'getheaders') else meta.get_all
|
||||||
|
meta_length = meta_func("Content-Length")
|
||||||
|
file_size = None
|
||||||
|
if meta_length:
|
||||||
|
file_size = int(meta_length[0])
|
||||||
|
print("Downloading: {0} filename {1} Bytes: {2}".format(url, filename, file_size))
|
||||||
|
|
||||||
|
file_size_dl = 0
|
||||||
|
block_sz = 8192
|
||||||
|
while True:
|
||||||
|
buffer = u.read(block_sz)
|
||||||
|
if not buffer:
|
||||||
|
break
|
||||||
|
|
||||||
|
file_size_dl += len(buffer)
|
||||||
|
f.write(buffer)
|
||||||
|
|
||||||
|
status = "{0:16}".format(file_size_dl)
|
||||||
|
if file_size:
|
||||||
|
status += " [{0:6.2f}%]".format(file_size_dl * 100 / file_size)
|
||||||
|
status += chr(13)
|
||||||
|
print(status, end="")
|
||||||
|
print()
|
||||||
|
if(isDuplicate == True):
|
||||||
|
if(filecmp.cmp(f1,filename)):
|
||||||
|
print ("samefile:",f1,":",filename)
|
||||||
|
os.remove(filename)
|
||||||
|
return filename
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
mySite = Piwigo('https://pho.flywithu.com/')
|
||||||
|
mySite.pwg.session.login(username="flywithu", password="1q2w3e4r5t")
|
||||||
|
#categories=mySite.pwg.categories.getList(recursive="true")['categories']
|
||||||
|
|
||||||
|
#for cat in categories:
|
||||||
|
#print(cat)
|
||||||
|
|
||||||
|
imagesinfo=mySite.pwg.categories.getImages(recursive="true")['paging']
|
||||||
|
#print(imagesinfo['count'])
|
||||||
|
total=imagesinfo['count']
|
||||||
|
perpage = 300
|
||||||
|
pagecount = math.ceil(int(total)/perpage)
|
||||||
|
|
||||||
|
print ("pagecount :",pagecount)
|
||||||
|
for x in range(pagecount):
|
||||||
|
print("pagecount:",x)
|
||||||
|
images=mySite.pwg.categories.getImages(recursive="true",per_page=perpage,page=x)['images']
|
||||||
|
for image in images:
|
||||||
|
print(image['element_url'])
|
||||||
|
download_file(image['element_url'],"data",image['file'])
|
||||||
|
mySite.pwg.session.logout()
|
||||||
|
|
||||||
|
|
||||||
|
|
195
exif.py
Normal file
195
exif.py
Normal file
@ -0,0 +1,195 @@
|
|||||||
|
#!/usr/bin/env python3.7
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import os
|
||||||
|
import exifread
|
||||||
|
import datetime
|
||||||
|
import sys
|
||||||
|
from piwigo import *
|
||||||
|
from calendar import monthrange
|
||||||
|
import tinytag
|
||||||
|
|
||||||
|
|
||||||
|
sys.stdout.reconfigure(encoding='utf-8')
|
||||||
|
sys.stdin.reconfigure(encoding='utf-8')
|
||||||
|
exif_choice = "EXIF DateTimeOriginal"
|
||||||
|
|
||||||
|
mySite = Piwigo('https://pho.flywithu.com/')
|
||||||
|
mySite.pwg.session.login(username="flywithu", password="1q2w3e4r5t")
|
||||||
|
|
||||||
|
#aaa=mySite.pwg.categories.add(name="zaza")
|
||||||
|
#print(aaa['id'])
|
||||||
|
#exit()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
categories=mySite.pwg.categories.getList(recursive="true")['categories']
|
||||||
|
categoryidnames = []
|
||||||
|
for category in categories:
|
||||||
|
# print (category['id_uppercat'])
|
||||||
|
categoryidname={'id':category['id'] , 'name':category['name'], 'id_uppercat':category['id_uppercat']}
|
||||||
|
categoryidnames.append(categoryidname)
|
||||||
|
|
||||||
|
#print(categoryidnames)
|
||||||
|
|
||||||
|
def getcategoryfromid(id):
|
||||||
|
|
||||||
|
for cat in categoryidnames:
|
||||||
|
# print(cat['id'])
|
||||||
|
if int(cat['id']) ==int(id):
|
||||||
|
return cat['name']
|
||||||
|
return id
|
||||||
|
|
||||||
|
#print("NAME::::::::"+str(getcategoryfromid(2930)))
|
||||||
|
|
||||||
|
#:wqexit()
|
||||||
|
#print(categoryidnames)
|
||||||
|
findcategorys = []
|
||||||
|
for category in categories:
|
||||||
|
if category['id_uppercat'] is None:
|
||||||
|
findcategory={'id':category['id'], 'name':category['name']}
|
||||||
|
findcategorys.append(findcategory)
|
||||||
|
#print (findcategorys)
|
||||||
|
elif (len(category['uppercats'].split(','))) is 2:
|
||||||
|
id_upper=category['id_uppercat']
|
||||||
|
findcategory={'id':category['id'], 'name':getcategoryfromid(id_upper)+"/"+category['name']}
|
||||||
|
findcategorys.append(findcategory)
|
||||||
|
elif (len(category['uppercats'].split(','))) is 3:
|
||||||
|
id_upper=category['id_uppercat']
|
||||||
|
id_upper2=""
|
||||||
|
for category2 in categories:
|
||||||
|
# print(str(category2['id'])+":"+id_upper)
|
||||||
|
if str(category2['id']) == id_upper:
|
||||||
|
id_upper2=category2['id_uppercat']
|
||||||
|
break
|
||||||
|
findcategory={'id':category['id'], 'name':getcategoryfromid(id_upper2)+"/"+getcategoryfromid(id_upper)+"/"+category['name']}
|
||||||
|
findcategorys.append(findcategory)
|
||||||
|
# print (category['name'])
|
||||||
|
|
||||||
|
|
||||||
|
def getidbyname(year):
|
||||||
|
global findcategorys
|
||||||
|
name=year
|
||||||
|
for findcat in findcategorys:
|
||||||
|
# print(findcat)
|
||||||
|
if findcat['name'] == name:
|
||||||
|
return findcat['id']
|
||||||
|
|
||||||
|
newid=mySite.pwg.categories.add(name=year,status="private")
|
||||||
|
findcategory={'id':newid['id'], 'name':name}
|
||||||
|
findcategorys.append(findcategory)
|
||||||
|
return newid['id']
|
||||||
|
|
||||||
|
def getidbyname2(year,month):
|
||||||
|
global findcategorys
|
||||||
|
name=year+"/"+month
|
||||||
|
for findcat in findcategorys:
|
||||||
|
# print(findcat)
|
||||||
|
if findcat['name'] == name:
|
||||||
|
return findcat['id']
|
||||||
|
|
||||||
|
yearid=getidbyname(year)
|
||||||
|
# print("YEARID:::"+str(yearid))
|
||||||
|
newid=mySite.pwg.categories.add(name=month,parent=int(yearid),status="private")
|
||||||
|
findcategory={'id':newid['id'], 'name':name}
|
||||||
|
findcategorys.append(findcategory)
|
||||||
|
return newid['id']
|
||||||
|
|
||||||
|
def getidbyname3(year,month,day):
|
||||||
|
global findcategorys
|
||||||
|
name=year+"/"+month+"/"+day
|
||||||
|
for findcat in findcategorys:
|
||||||
|
# print(findcat)
|
||||||
|
if findcat['name'] == name:
|
||||||
|
return findcat['id']
|
||||||
|
|
||||||
|
monthid=getidbyname2(year,month)
|
||||||
|
# print("Monthid:::"+str(monthid))
|
||||||
|
newid=mySite.pwg.categories.add(name=day,parent=int(monthid),status="private")
|
||||||
|
findcategory={'id':newid['id'], 'name':name}
|
||||||
|
findcategorys.append(findcategory)
|
||||||
|
return newid['id']
|
||||||
|
|
||||||
|
|
||||||
|
#print(str(getidbyname3("2017","05","1_59")))
|
||||||
|
#print(str(getidbyname3("2017","05","1_59")))
|
||||||
|
#print(str(getidbyname3("2017","05","1_59")))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#exit()
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
testfiles = [ x for x in filenames if os.path.isfile(os.path.join(folder,x)) == True ]
|
||||||
|
#print (testfiles)
|
||||||
|
|
||||||
|
#exit()
|
||||||
|
#def print_all_metadata_atoms(file):
|
||||||
|
# atoms = file.findall('.//data')
|
||||||
|
# for atom in atoms:
|
||||||
|
# data = atom.get_attribute('data')
|
||||||
|
# print (atom.parent.name, data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#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