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:
angelblue05 2016-02-04 19:09:47 -06:00
parent afcb3461b4
commit 256d98c6f3
2 changed files with 15 additions and 4 deletions

View file

@ -105,17 +105,17 @@ class LibrarySync(threading.Thread):
lastSync = "2010-01-01T00:00:00Z"
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)
# get server RetentionDateTime
url = "{server}/Emby.Kodi.SyncQueue/GetServerDateTime?format=json"
result = self.doUtils.downloadUrl(url)
retention_time = "2010-01-01T00:00:00Z"
if result and result.get("RetentionDateTime"):
if result and result.get('RetentionDateTime'):
self.logMsg("RetentionDateTime Found", 1)
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)
# if last sync before retention time do a full sync
@ -155,7 +155,7 @@ class LibrarySync(threading.Thread):
result = self.doUtils.downloadUrl(url)
try: # datetime fails when used more than once, TypeError
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:
# If the server plugin is not installed or an error happened.

View file

@ -6,6 +6,7 @@ import cProfile
import inspect
import pstats
import sqlite3
from datetime import datetime, time
import time
import unicodedata
import xml.etree.ElementTree as etree
@ -238,6 +239,16 @@ def stopProfiling(pr, profileName):
"{0}".format(cumulative_time), func_name, filename))
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):
# For video nodes
text = text.replace(":", "")