Code style and module guard
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
import requests
|
import datetime
|
||||||
import xml.etree.ElementTree as ET
|
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import datetime
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
# Prepare and send the propfind request return xml string
|
# Prepare and send the propfind request return xml string
|
||||||
def propfind(path, auth):
|
def propfind(path, auth):
|
||||||
@@ -16,6 +18,7 @@ def propfind(path,auth):
|
|||||||
resp = s.send(prepped)
|
resp = s.send(prepped)
|
||||||
return resp.text
|
return resp.text
|
||||||
|
|
||||||
|
|
||||||
# Function iterates through the given xml which contains all files and folders in the provided path
|
# Function iterates through the given xml which contains all files and folders in the provided path
|
||||||
def search_folder(requestreturn):
|
def search_folder(requestreturn):
|
||||||
# List to collect path of folders stored in path
|
# List to collect path of folders stored in path
|
||||||
@@ -44,13 +47,15 @@ def search_folder(requestreturn):
|
|||||||
else:
|
else:
|
||||||
for t in p.findall('.//{DAV:}getlastmodified'):
|
for t in p.findall('.//{DAV:}getlastmodified'):
|
||||||
# this function converts the given date to unix timestamp
|
# 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
|
# 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:
|
if lastmodified < 631148400:
|
||||||
for fileid in p.findall('.//{http://owncloud.org/ns}fileid'):
|
for fileid in p.findall('.//{http://owncloud.org/ns}fileid'):
|
||||||
linkswrongtime.append(fileid.text)
|
linkswrongtime.append(fileid.text)
|
||||||
return [innerfolders, linkswrongtime]
|
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
|
# 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):
|
def version_check(xmlfile):
|
||||||
tree = ET.ElementTree(ET.fromstring(xmlfile))
|
tree = ET.ElementTree(ET.fromstring(xmlfile))
|
||||||
@@ -69,7 +74,8 @@ def version_check(xmlfile):
|
|||||||
for t in p.findall('.//{DAV:}getlastmodified'):
|
for t in p.findall('.//{DAV:}getlastmodified'):
|
||||||
if not (t.text is None):
|
if not (t.text is None):
|
||||||
# this function converts the given date to unix timestamp
|
# 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:
|
if lastmodified > most_current_timestamp:
|
||||||
most_current_timestamp = lastmodified
|
most_current_timestamp = lastmodified
|
||||||
@@ -83,7 +89,8 @@ def version_check(xmlfile):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def main():
|
|
||||||
|
if __name__ == "__main__":
|
||||||
# Enter username and password to enter nextcloud via webdav
|
# Enter username and password to enter nextcloud via webdav
|
||||||
user = sys.argv[1]
|
user = sys.argv[1]
|
||||||
passw = sys.argv[2]
|
passw = sys.argv[2]
|
||||||
@@ -112,5 +119,3 @@ def main():
|
|||||||
version_path = prefix_path + version_suffix
|
version_path = prefix_path + version_suffix
|
||||||
versions = propfind(version_path, auth)
|
versions = propfind(version_path, auth)
|
||||||
print(version_check(versions))
|
print(version_check(versions))
|
||||||
|
|
||||||
main()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user