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

4 years ago
  1. import requests
  2. import xml.etree.ElementTree as ET
  3. import sys
  4. def propfind(path,auth):
  5. headers = {"Depth":"1"}
  6. req = r = requests.Request("PROPFIND", path, headers=headers, auth=auth)
  7. prepped = req.prepare()
  8. s = requests.Session()
  9. resp = s.send(prepped)
  10. return resp.text
  11. def search_folder(requestreturn):
  12. innerfolders = []
  13. linkswrongtime = []
  14. firstfolder = True
  15. temp = "this is sa temporary storage"
  16. tree = ET.ElementTree(ET.fromstring(requestreturn))
  17. for resp in tree.findall('.//{DAV:}response'):
  18. for p in resp:
  19. if not(p.text is None):
  20. if (p.text[-1] == '/'):
  21. if not(firstfolder):
  22. innerfolders.append(p.text)
  23. else:
  24. firstfolder = False
  25. break
  26. else:
  27. temp = p.text
  28. else:
  29. for time in p.findall('.//{DAV:}getlastmodified'):
  30. year = time.text.split(' ')
  31. if int(year[3]) < 1990:
  32. linkswrongtime.append(temp)
  33. return [innerfolders, linkswrongtime]
  34. user = sys.argv[1]
  35. passw = sys.argv[2]
  36. auth = requests.auth.HTTPBasicAuth(user,passw)
  37. prefix_path = "https://kingsx.cs.uni-saarland.de"
  38. mainpath = "/remote.php/dav/files/"+ user + "/Testrequests/"
  39. folders = [mainpath]
  40. wrongtime = []
  41. while folders:
  42. path_suffix = folders.pop(0)
  43. path = prefix_path + str(path_suffix)
  44. r = propfind(path,auth)
  45. res = search_folder(r)
  46. folders = folders + res[0]
  47. wrongtime = wrongtime + res[1]
  48. print(wrongtime)
  49. version_suffix = "/remote.php/dav/versions/USER/versions/FILEID"