Fix datetime error
Known kodi/python issue where datetime.strptime throws a Nonetype error for no reason, after being used once.
This commit is contained in:
parent
afcb3461b4
commit
256d98c6f3
2 changed files with 15 additions and 4 deletions
|
@ -105,17 +105,17 @@ class LibrarySync(threading.Thread):
|
||||||
lastSync = "2010-01-01T00:00:00Z"
|
lastSync = "2010-01-01T00:00:00Z"
|
||||||
self.logMsg("Last sync run: %s" % lastSync, 1)
|
self.logMsg("Last sync run: %s" % lastSync, 1)
|
||||||
|
|
||||||
lastSyncTime = datetime.strptime(lastSync, "%Y-%m-%dT%H:%M:%SZ")
|
lastSyncTime = utils.convertdate(lastSync)
|
||||||
self.logMsg("LastIncrementalSync : %s" % lastSyncTime, 1)
|
self.logMsg("LastIncrementalSync : %s" % lastSyncTime, 1)
|
||||||
|
|
||||||
# get server RetentionDateTime
|
# get server RetentionDateTime
|
||||||
url = "{server}/Emby.Kodi.SyncQueue/GetServerDateTime?format=json"
|
url = "{server}/Emby.Kodi.SyncQueue/GetServerDateTime?format=json"
|
||||||
result = self.doUtils.downloadUrl(url)
|
result = self.doUtils.downloadUrl(url)
|
||||||
retention_time = "2010-01-01T00:00:00Z"
|
retention_time = "2010-01-01T00:00:00Z"
|
||||||
if result and result.get("RetentionDateTime"):
|
if result and result.get('RetentionDateTime'):
|
||||||
self.logMsg("RetentionDateTime Found", 1)
|
self.logMsg("RetentionDateTime Found", 1)
|
||||||
retention_time = result['RetentionDateTime']
|
retention_time = result['RetentionDateTime']
|
||||||
retention_time = datetime.strptime(retention_time, "%Y-%m-%dT%H:%M:%SZ")
|
retention_time = utils.convertdate(retention_time)
|
||||||
self.logMsg("RetentionDateTime : %s" % retention_time, 1)
|
self.logMsg("RetentionDateTime : %s" % retention_time, 1)
|
||||||
|
|
||||||
# if last sync before retention time do a full sync
|
# if last sync before retention time do a full sync
|
||||||
|
@ -155,7 +155,7 @@ class LibrarySync(threading.Thread):
|
||||||
result = self.doUtils.downloadUrl(url)
|
result = self.doUtils.downloadUrl(url)
|
||||||
try: # datetime fails when used more than once, TypeError
|
try: # datetime fails when used more than once, TypeError
|
||||||
server_time = result['ServerDateTime']
|
server_time = result['ServerDateTime']
|
||||||
server_time = datetime.strptime(server_time, "%Y-%m-%dT%H:%M:%SZ")
|
server_time = utils.convertdate(server_time)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# If the server plugin is not installed or an error happened.
|
# If the server plugin is not installed or an error happened.
|
||||||
|
|
|
@ -6,6 +6,7 @@ import cProfile
|
||||||
import inspect
|
import inspect
|
||||||
import pstats
|
import pstats
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
from datetime import datetime, time
|
||||||
import time
|
import time
|
||||||
import unicodedata
|
import unicodedata
|
||||||
import xml.etree.ElementTree as etree
|
import xml.etree.ElementTree as etree
|
||||||
|
@ -238,6 +239,16 @@ def stopProfiling(pr, profileName):
|
||||||
"{0}".format(cumulative_time), func_name, filename))
|
"{0}".format(cumulative_time), func_name, filename))
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
def convertdate(date):
|
||||||
|
try:
|
||||||
|
date = datetime.strptime(date, "%Y-%m-%dT%H:%M:%SZ")
|
||||||
|
except TypeError:
|
||||||
|
# TypeError: attribute of type 'NoneType' is not callable
|
||||||
|
# Known Kodi/python error
|
||||||
|
date = datetime(*(time.strptime(date, "%Y-%m-%dT%H:%M:%SZ")[0:6]))
|
||||||
|
|
||||||
|
return date
|
||||||
|
|
||||||
def normalize_nodes(text):
|
def normalize_nodes(text):
|
||||||
# For video nodes
|
# For video nodes
|
||||||
text = text.replace(":", "")
|
text = text.replace(":", "")
|
||||||
|
|
Loading…
Reference in a new issue