2015-04-16, 12:04
Hi.
I'm trying to get current time and add some minutes in python script for an addon.
Here is my code :
But I run the addon, I have this error :
I have made an ugly workaround by calculating by myself :
Because ListItem.EndTime is only available for TV programms or PVR :
http://kodi.wiki/view/InfoLabels#Listitem
We can't use time function in addon ?
I'm trying to get current time and add some minutes in python script for an addon.
Here is my code :
Code:
import xbmc, xbmcaddon, xbmcgui
from datetime import datetime, timedelta, time
def _get_end_time(minutes_string):
now = datetime.now().time()
full_minutes = int(minutes_string)
fulldate = datetime(2000, 1, 1, now.hour, now.minute, now.second)
fulldate = fulldate + datetime.timedelta(seconds=full_minutes)
return fulldate.time()
But I run the addon, I have this error :
Code:
10:55:04 T:4860 ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <type 'exceptions.ImportError'>
Error Contents: Failed to import time because the import lockis held by another thread.
Traceback (most recent call last):
File "C:\Kodi-14.0\portable_data\addons\script.duration\default.py", line 98, in <module>
Main()
File "C:\Kodi-14.0\portable_data\addons\script.duration\default.py", line 52, in __init__
self.run_backend()
File "C:\Kodi-14.0\portable_data\addons\script.duration\default.py", line 81, in run_backend
self.display_duration()
File "C:\Kodi-14.0\portable_data\addons\script.duration\default.py", line 91, in display_duration
end_time = _get_end_time(self.duration)
File "C:\Kodi-14.0\portable_data\addons\script.duration\default.py", line 36, in _get_end_time
now = datetime.now().time()
ImportError: Failed to import time because the import lockis held by another thread.
-->End of Python script error report<--
I have made an ugly workaround by calculating by myself :
Code:
def _get_end_time(minutes_string):
try:
now = xbmc.getInfoLabel("System.Time(hh:mm)")
# Extract hours and minutes from time and convert to integer
hh = int(now[0:2])
mm = int(now[3:5])
# Convert minutes to integer
full_minutes = int(minutes_string)
# Get minutes and hours from duration with modulo division
minutes = full_minutes % 60
hours = full_minutes // 60
# Add hours and minutes to current time
mm = mm + minutes
hh = hh + hours
# Convert minutes to hours with minutes greater than 60
hh = hh + (mm // 60)
mm = mm % 60
# Convert hours greater than 24
hh = hh % 24
return str(hh).zfill(2)+":"+str(mm).zfill(2)
except:
return '--:--'
Because ListItem.EndTime is only available for TV programms or PVR :
http://kodi.wiki/view/InfoLabels#Listitem
We can't use time function in addon ?