Fix broken modification dates in Nextcloud folders
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.5 KiB

import requests
import xml.etree.ElementTree as ET
import sys
def propfind(path,auth):
headers = {"Depth":"1"}
req = r = requests.Request("PROPFIND", path, headers=headers, auth=auth)
prepped = req.prepare()
s = requests.Session()
resp = s.send(prepped)
return resp.text
def search_folder(requestreturn):
innerfolders = []
linkswrongtime = []
firstfolder = True
temp = "this is sa temporary storage"
tree = ET.ElementTree(ET.fromstring(requestreturn))
for resp in tree.findall('.//{DAV:}response'):
for p in resp:
if not(p.text is None):
if (p.text[-1] == '/'):
if not(firstfolder):
innerfolders.append(p.text)
else:
firstfolder = False
break
else:
temp = p.text
else:
for time in p.findall('.//{DAV:}getlastmodified'):
year = time.text.split(' ')
if int(year[3]) < 1990:
linkswrongtime.append(temp)
return [innerfolders, linkswrongtime]
user = sys.argv[1]
passw = sys.argv[2]
auth = requests.auth.HTTPBasicAuth(user,passw)
prefix_path = "https://kingsx.cs.uni-saarland.de"
mainpath = "/remote.php/dav/files/"+ user + "/Testrequests/"
folders = [mainpath]
wrongtime = []
while folders:
path_suffix = folders.pop(0)
path = prefix_path + str(path_suffix)
r = propfind(path,auth)
res = search_folder(r)
folders = folders + res[0]
wrongtime = wrongtime + res[1]
print(wrongtime)
version_suffix = "/remote.php/dav/versions/USER/versions/FILEID"