Advertisement
Guest User

Untitled

a guest
Oct 9th, 2014
1,074
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. import xbmc
  2. import xbmcaddon, os, time
  3. import subprocess
  4. import sqlite3
  5.  
  6.  
  7. addon = xbmcaddon.Addon('script.tvguide')
  8. datapath = addon.getAddonInfo('profile').decode('utf-8')
  9. wd = xbmc.translatePath(os.path.join(datapath, 'xmltv'))
  10. wb = xbmc.translatePath(os.path.join(datapath, 'xmltv/mk_xmltv.bat'))
  11. startupinfo = subprocess.STARTUPINFO()
  12. startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
  13.  
  14.  
  15. # if the xmltv.xml file is out of date, execute the mk_xmltv.bat to rebuild xmltv.xml
  16. build_xml=True
  17. if (os.path.exists(wd+'\\xmltv.xml')):
  18. if (time.time() - (os.path.getmtime(wd+'\\xmltv.xml')) < 60*60*24*7):
  19. build_xml=False
  20.  
  21. if (build_xml):
  22. p = subprocess.Popen( wb, startupinfo=startupinfo, cwd=wd)
  23. stdout, stderr = p.communicate()
  24.  
  25. # drop the tvguide source.db programs table only, create again and add indexes - this speeds up the update from xmltv.xml significantly and avoids duplicate entries
  26. try:
  27. databasePath = xbmc.translatePath(datapath)+'\\source.db'
  28. conn = sqlite3.connect(databasePath, detect_types=sqlite3.PARSE_DECLTYPES)
  29. conn.execute('PRAGMA foreign_keys = ON')
  30. conn.row_factory = sqlite3.Row
  31. c = conn.cursor()
  32. c.execute('DROP TABLE programs')
  33. c.execute('CREATE TABLE programs(channel TEXT, title TEXT, start_date TIMESTAMP, end_date TIMESTAMP, description TEXT, image_large TEXT, image_small TEXT, source TEXT, updates_id INTEGER, FOREIGN KEY(channel, source) REFERENCES channels(id, source) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY(updates_id) REFERENCES updates(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED)')
  34. c.execute('CREATE INDEX program_list_idx ON programs(source, channel, start_date, end_date)')
  35. c.execute('CREATE INDEX start_date_idx ON programs(start_date)')
  36. c.execute('CREATE INDEX end_date_idx ON programs(end_date)')
  37. conn.commit()
  38. c.close()
  39. except sqlite3.OperationalError, ex:
  40. pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement