Browse Source

Nextcloud crawler via WebDav

main
Lisa-Hoffmann 2 years ago
committed by GitHub
parent
commit
7e91eb53ea
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 56
      trying_to_fix_nextcloud.py

56
trying_to_fix_nextcloud.py

@ -0,0 +1,56 @@
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.arcv[1]
passw = sys.arcv[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"
Loading…
Cancel
Save