Browse Source

Code style and module guard

main
Frederik Möllers 2 years ago
parent
commit
912d3af794
  1. 21
      trying_to_fix_nextcloud.py

21
trying_to_fix_nextcloud.py

@ -1,8 +1,10 @@
import requests
import xml.etree.ElementTree as ET
import datetime
import sys
import time
import datetime
import xml.etree.ElementTree as ET
import requests
# Prepare and send the propfind request return xml string
def propfind(path, auth):
@ -16,6 +18,7 @@ def propfind(path,auth):
resp = s.send(prepped)
return resp.text
# Function iterates through the given xml which contains all files and folders in the provided path
def search_folder(requestreturn):
# List to collect path of folders stored in path
@ -44,13 +47,15 @@ def search_folder(requestreturn):
else:
for t in p.findall('.//{DAV:}getlastmodified'):
# this function converts the given date to unix timestamp
lastmodified = time.mktime(datetime.datetime.strptime(t.text, "%a, %d %b %Y %H:%M:%S GMT").timetuple())
lastmodified = time.mktime(
datetime.datetime.strptime(t.text, "%a, %d %b %Y %H:%M:%S GMT").timetuple())
# 631148400 is the unix timestamp of 01.01.1990 00:00:00, because we know there is no file older than this in our nextcloud system
if lastmodified < 631148400:
for fileid in p.findall('.//{http://owncloud.org/ns}fileid'):
linkswrongtime.append(fileid.text)
return [innerfolders, linkswrongtime]
# This function returns the fileid of the version of a given fileid with the most current timestamp or None if there are no versions with a timestamp younger than 01.01.1990
def version_check(xmlfile):
tree = ET.ElementTree(ET.fromstring(xmlfile))
@ -69,7 +74,8 @@ def version_check(xmlfile):
for t in p.findall('.//{DAV:}getlastmodified'):
if not (t.text is None):
# this function converts the given date to unix timestamp
lastmodified = time.mktime(datetime.datetime.strptime(t.text, "%a, %d %b %Y %H:%M:%S GMT").timetuple())
lastmodified = time.mktime(
datetime.datetime.strptime(t.text, "%a, %d %b %Y %H:%M:%S GMT").timetuple())
#
if lastmodified > most_current_timestamp:
most_current_timestamp = lastmodified
@ -83,7 +89,8 @@ def version_check(xmlfile):
else:
return None
def main():
if __name__ == "__main__":
# Enter username and password to enter nextcloud via webdav
user = sys.argv[1]
passw = sys.argv[2]
@ -112,5 +119,3 @@ def main():
version_path = prefix_path + version_suffix
versions = propfind(version_path, auth)
print(version_check(versions))
main()
Loading…
Cancel
Save