Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import xbmc
- import xbmcgui
- import xbmcaddon
- import os
- import threading
- import datetime
- import time
- import urllib2
- import StringIO
- import sqlite3
- import threading
- from sqlite3 import dbapi2 as database
- from xml.etree import ElementTree
- import xml.etree.ElementTree as ET
- from UserDict import DictMixin
- __killthread__ = False
- #get actioncodes from keyboard.xml
- ACTION_ENTER = 7
- ACTION_BACKSPACE = 110
- def cSetVisible(WiNdOw,iD,V=True): WiNdOw.getControl(iD).setVisible(V)
- ADDON = xbmcaddon.Addon(id = 'script.tvguide')
- class OrderedDict(dict, DictMixin):
- def __init__(self, *args, **kwds):
- if len(args) > 1:
- raise TypeError('expected at most 1 arguments, got %d' % len(args))
- try:
- self.__end
- except AttributeError:
- self.clear()
- self.update(*args, **kwds)
- def clear(self):
- self.__end = end = []
- end += [None, end, end] # sentinel node for doubly linked list
- self.__map = {} # key --> [key, prev, next]
- dict.clear(self)
- def __setitem__(self, key, value):
- if key not in self:
- end = self.__end
- curr = end[1]
- curr[2] = end[1] = self.__map[key] = [key, curr, end]
- dict.__setitem__(self, key, value)
- def __delitem__(self, key):
- dict.__delitem__(self, key)
- key, prev, next = self.__map.pop(key)
- prev[2] = next
- next[1] = prev
- def __iter__(self):
- end = self.__end
- curr = end[2]
- while curr is not end:
- yield curr[0]
- curr = curr[2]
- def __reversed__(self):
- end = self.__end
- curr = end[1]
- while curr is not end:
- yield curr[0]
- curr = curr[1]
- def popitem(self, last=True):
- if not self:
- raise KeyError('dictionary is empty')
- if last:
- key = reversed(self).next()
- else:
- key = iter(self).next()
- value = self.pop(key)
- return key, value
- def __reduce__(self):
- items = [[k, self[k]] for k in self]
- tmp = self.__map, self.__end
- del self.__map, self.__end
- inst_dict = vars(self).copy()
- self.__map, self.__end = tmp
- if inst_dict:
- return (self.__class__, (items,), inst_dict)
- return self.__class__, (items,)
- def keys(self):
- return list(self)
- setdefault = DictMixin.setdefault
- update = DictMixin.update
- pop = DictMixin.pop
- values = DictMixin.values
- items = DictMixin.items
- iterkeys = DictMixin.iterkeys
- itervalues = DictMixin.itervalues
- iteritems = DictMixin.iteritems
- def __repr__(self):
- if not self:
- return '%s()' % (self.__class__.__name__,)
- return '%s(%r)' % (self.__class__.__name__, self.items())
- def copy(self):
- return self.__class__(self)
- @classmethod
- def fromkeys(cls, iterable, value=None):
- d = cls()
- for key in iterable:
- d[key] = value
- return d
- def __eq__(self, other):
- if isinstance(other, OrderedDict):
- if len(self) != len(other):
- return False
- for p, q in zip(self.items(), other.items()):
- if p != q:
- return False
- return True
- return dict.__eq__(self, other)
- def __ne__(self, other):
- return not self == other
- class MyClass(xbmcgui.WindowXML):
- def onInit(self):
- pass
- def timer1_8percent(self):
- for i in range(1):
- time.sleep(1)
- self.getControl(4202).setLabel("8%")
- def timer1_12percent(self):
- for i in range(1):
- time.sleep(2)
- self.getControl(4202).setLabel("12%")
- def timer1_18percent(self):
- for i in range(1):
- time.sleep(3)
- self.getControl(4202).setLabel("18%")
- def timer1_24percent(self):
- for i in range(1):
- time.sleep(4)
- self.getControl(4202).setLabel("24%")
- def timer1_28percent(self):
- for i in range(1):
- time.sleep(5)
- self.getControl(4202).setLabel("28%")
- def timer1_32percent(self):
- for i in range(1):
- time.sleep(6)
- self.getControl(4202).setLabel("32%")
- def timer1_38percent(self):
- for i in range(1):
- time.sleep(7)
- self.getControl(4202).setLabel("38%")
- def timer1_42percent(self):
- for i in range(1):
- time.sleep(8)
- self.getControl(4202).setLabel("42%")
- def timer1_48percent(self):
- for i in range(1):
- time.sleep(9)
- self.getControl(4202).setLabel("48%")
- def timer1_56percent(self):
- for i in range(1):
- time.sleep(10)
- self.getControl(4202).setLabel("56%")
- def timer1_64percent(self):
- for i in range(1):
- time.sleep(11)
- self.getControl(4202).setLabel("64%")
- def timer1_72percent(self):
- for i in range(1):
- time.sleep(12)
- self.getControl(4202).setLabel("72%")
- def timer1_78percent(self):
- for i in range(1):
- time.sleep(13)
- self.getControl(4202).setLabel("78%")
- def timer1_86percent(self):
- for i in range(1):
- time.sleep(14)
- self.getControl(4202).setLabel("86%")
- def timer1_92percent(self):
- for i in range(1):
- time.sleep(15)
- self.getControl(4202).setLabel("92%")
- def timer1_96percent(self):
- for i in range(1):
- time.sleep(16)
- self.getControl(4202).setLabel("96%")
- def timer1_98percent(self):
- for i in range(1):
- time.sleep(17)
- self.getControl(4202).setLabel("98%")
- def timer1_100percent(self):
- for i in range(1):
- time.sleep(18)
- self.getControl(4202).setLabel("100%")
- def allchannels_timer(self):
- while __killthread__ is False:
- time.sleep(0.3)
- self.getControl(4202).setLabel("0%")
- #DOWNLOAD THE XML SOURCE HERE
- url = ADDON.getSetting('allchannel.url')
- req = urllib2.Request(url)
- response = urllib2.urlopen(req)
- data = response.read()
- response.close()
- profilePath = xbmc.translatePath(os.path.join('special://userdata/addon_data/script.tvguide', ''))
- self.getControl(4202).setLabel("1%")
- self.thread = threading.Thread(target=self.timer1_8percent)
- self.thread.setDaemon(True)
- self.thread.start()
- self.thread = threading.Thread(target=self.timer1_12percent)
- self.thread.setDaemon(True)
- self.thread.start()
- self.thread = threading.Thread(target=self.timer1_18percent)
- self.thread.setDaemon(True)
- self.thread.start()
- self.thread = threading.Thread(target=self.timer1_24percent)
- self.thread.setDaemon(True)
- self.thread.start()
- self.thread = threading.Thread(target=self.timer1_28percent)
- self.thread.setDaemon(True)
- self.thread.start()
- self.thread = threading.Thread(target=self.timer1_32percent)
- self.thread.setDaemon(True)
- self.thread.start()
- if os.path.exists(profilePath):
- profilePath = profilePath + 'source.db'
- con = database.connect(profilePath)
- cur = con.cursor()
- cur.execute('CREATE TABLE programs(channel TEXT, title TEXT, start_date TIMESTAMP, stop_date TIMESTAMP, description TEXT)')
- con.commit()
- con.close
- tv_elem = ElementTree.parse(StringIO.StringIO(data)).getroot()
- profilePath = xbmc.translatePath(os.path.join('special://userdata/addon_data/script.tvguide', ''))
- profilePath = profilePath + 'source.db'
- con = sqlite3.connect(profilePath)
- cur = con.cursor()
- channels = OrderedDict()
- self.thread = threading.Thread(target=self.timer1_38percent)
- self.thread.setDaemon(True)
- self.thread.start()
- self.thread = threading.Thread(target=self.timer1_42percent)
- self.thread.setDaemon(True)
- self.thread.start()
- self.thread = threading.Thread(target=self.timer1_48percent)
- self.thread.setDaemon(True)
- self.thread.start()
- self.thread = threading.Thread(target=self.timer1_56percent)
- self.thread.setDaemon(True)
- self.thread.start()
- self.thread = threading.Thread(target=self.timer1_64percent)
- self.thread.setDaemon(True)
- self.thread.start()
- self.thread = threading.Thread(target=self.timer1_72percent)
- self.thread.setDaemon(True)
- self.thread.start()
- self.thread = threading.Thread(target=self.timer1_78percent)
- self.thread.setDaemon(True)
- self.thread.start()
- self.thread = threading.Thread(target=self.timer1_86percent)
- self.thread.setDaemon(True)
- self.thread.start()
- self.thread = threading.Thread(target=self.timer1_92percent)
- self.thread.setDaemon(True)
- self.thread.start()
- self.thread = threading.Thread(target=self.timer1_96percent)
- self.thread.setDaemon(True)
- self.thread.start()
- self.thread = threading.Thread(target=self.timer1_98percent)
- self.thread.setDaemon(True)
- self.thread.start()
- self.thread = threading.Thread(target=self.timer1_100percent)
- self.thread.setDaemon(True)
- self.thread.start()
- # Get the loaded data
- for channel in tv_elem.findall('channel'):
- channel_name = channel.find('display-name').text
- for program in channel.findall('programme'):
- title = program.find('title').text
- start_time = program.get("start")
- stop_time = program.get("stop")
- cur.execute("INSERT INTO programs(channel, title, start_date, stop_date)" + " VALUES(?, ?, ?, ?)", [channel_name, title, start_time, stop_time])
- con.commit()
- con.close
- print 'Channels store into database are now successfully!'
- program = None
- now = datetime.datetime.now()
- #strCh = '(\'' + '\',\''.join(channelMap.keys()) + '\')'
- cur.execute('SELECT channel, title, start_date, stop_date FROM programs WHERE channel')
- getprogram_info = cur.fetchall()
- for row in getprogram_info:
- programming = row[0], row[1], row[2], row[3]
- print programming
- #print row[0], row[1], row[2], row[3]
- #programming = row[0], row[1], row[2], row[3]
- #programming = row[0], row[1], row[2], row[3]
- #cur.close()
- def onAction(self, action):
- if action == ACTION_BACKSPACE:
- __killthread__ = True
- self.thread.join(0.0)
- profilePath = xbmc.translatePath(os.path.join('special://userdata/addon_data/script.tvguide', ''))
- database_source = profilePath + 'source.db'
- write_source = profilePath + 'source.db-journal'
- os.remove(write_source)
- os.remove(database_source)
- if action == ACTION_ENTER:
- self.thread = threading.Thread(target=self.allchannels_timer)
- self.thread.setDaemon(True)
- self.thread.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement