2014-09-06, 23:40
Hi guys,
I'm working on my python script to create the button for tv programs.
I know how to create the variable to get the program title for the programs which I have to pull the data from the sqlite database.
I can also create the variable for the height with size I want, but I have no idea how to work out the program times to get the width size for the button control.
Here is the code I use:
I use this to get the start date and end date format from sqlite database:
Here is the start date for each channel:
Here is the end date for each channel:
When you workout the two different formats, example: 20140520170000 and 20140520180000 which is make one hour then convert it to make the width size for per program.
Do you know how?
I'm working on my python script to create the button for tv programs.
I know how to create the variable to get the program title for the programs which I have to pull the data from the sqlite database.
I can also create the variable for the height with size I want, but I have no idea how to work out the program times to get the width size for the button control.
Here is the code I use:
Code:
#get the programs list
cur.execute('SELECT channel, title, start_date, stop_date FROM programs WHERE channel="channel"')
programList = list()
programs = cur.fetchall()
for row in programs:
program = row[1].encode('ascii'), str(row[2]), str(row[3])
program_title = row[1].encode('ascii')
program_startdate = str(row[2])
program_endDate = str(row[3])
# find nearest half hour
viewStartDate = datetime.datetime.now()
viewStartDate -= datetime.timedelta(minutes = viewStartDate.minute % 30, seconds = viewStartDate.second)
try:
start_date = datetime.datetime.strptime(program_startdate, "%Y%m%d%H%M%S")
end_date = datetime.datetime.strptime(program_endDate, "%Y%m%d%H%M%S")
except TypeError:
start_date = datetime.datetime.fromtimestamp(time.mktime(time.strptime(program_startdate, "%Y%m%d%H%M%S")))
end_date = datetime.datetime.fromtimestamp(time.mktime(time.strptime(program_endDate, "%Y%m%d%H%M%S")))
idx = str(program)
notificationScheduled = program
#convert the datetime object between start_date and end_date
startDelta = start_date - viewStartDate
stopDelta = end_date - viewStartDate
program_start = self.secondsToXposition(startDelta.seconds)
if startDelta.days < 0:
program_start = self.epgView.left
program_width = self.secondsToXposition(stopDelta.seconds) - program_start
if program_start + program_width > self.epgView.right:
program_width = self.epgView.right - program_start
title = program_title
program_height = 38
programs_controls = xbmcgui.ControlButton(350, program_width * idx, 300, program_height, program_title)
self.addControl(programs_controls)
cur.close()
I use this to get the start date and end date format from sqlite database:
Code:
program_startdate = str(row[2])
program_endDate = str(row[3])
Here is the start date for each channel:
Code:
20140520170000
20140520170000
20140520170000
20140520170000
20140520170000
20140520170000
20140520170000
Here is the end date for each channel:
Code:
20140520173000
20140520180000
20140520183000
20140520173000
20140520180000
20140520180000
When you workout the two different formats, example: 20140520170000 and 20140520180000 which is make one hour then convert it to make the width size for per program.
Do you know how?