def main(): # log_add() print to stdout a text message crossepg.log_add("---- START EXAMPLE TEST SCRIPT ----") # get installation dir instdir = crossepg.epgdb_get_installroot() if instdir == False: crossepg.log_add("ERROR: cannot find CrossEPG installation directory") sys.exit(1) crossepg.log_add("Installation dir : %s" % instdir) # get dbroot path dbroot = crossepg.epgdb_get_dbroot() if dbroot == False: crossepg.log_add("ERROR: cannot find CrossEPG database directory") sys.exit(1) crossepg.log_add("Database dir : %s" % dbroot) # open CrossEPG internal database if crossepg.epgdb_open(dbroot): crossepg.log_add("EPGDB opened successfully (root = %s)" % dbroot); else: crossepg.log_add("Error opening EPGDB"); crossepg.epgdb_close(); sys.exit(1) crossepg.log_add("Closing EPGDB"); crossepg.epgdb_close(); delta_timezone = scriptlib.delta_utc() crossepg.log_add("GMT vs. LocalTime difference (in seconds): %d" % delta_timezone) delta_daylight = scriptlib.delta_dst() crossepg.log_add("DayLight Saving (DST) difference now: %d" % delta_daylight) crossepg.log_add("---- END EXAMPLE TEST SCRIPT ----")
def main(): # log_add() print to stdout a text message crossepg.log_add("---- START EXAMPLE TEST SCRIPT ----") # get installation dir instdir = crossepg.epgdb_get_installroot() if instdir == False: crossepg.log_add("ERROR: cannot find CrossEPG installation directory") sys.exit(1) crossepg.log_add("Installation dir : %s" % instdir) # get dbroot path dbroot = crossepg.epgdb_get_dbroot() if dbroot == False: crossepg.log_add("ERROR: cannot find CrossEPG database directory") sys.exit(1) crossepg.log_add("Database dir : %s" % dbroot) # open CrossEPG internal database if crossepg.epgdb_open(dbroot): crossepg.log_add("EPGDB opened successfully (root = %s)" % dbroot) else: crossepg.log_add("Error opening EPGDB") crossepg.epgdb_close() sys.exit(1) crossepg.log_add("Closing EPGDB") crossepg.epgdb_close() delta_timezone = scriptlib.delta_utc() crossepg.log_add("GMT vs. LocalTime difference (in seconds): %d" % delta_timezone) delta_daylight = scriptlib.delta_dst() crossepg.log_add("DayLight Saving (DST) difference now: %d" % delta_daylight) crossepg.log_add("---- END EXAMPLE TEST SCRIPT ----")
def __init__(self,confdir,dbroot): # initialize logging self.log = scriptlib.logging_class() # write to video OSD the script name self.log.log2video_scriptname(self.CONF_LOG_SCRIPT_NAME) self.log.log("=== RUNNING SCRIPT %s ===" % self.CONF_LOG_SCRIPT_NAME) CONF_FILE = os.path.join(confdir,self.CONF_CONFIGFILENAME) if not os.path.exists(CONF_FILE) : self.log.log("ERROR: %s not present" % CONF_FILE) sys.exit(1) config = ConfigParser.ConfigParser() config.optionxform = str # needed to return case sensitive index config.read(CONF_FILE) # reading [global] section options self.CONF_DEFAULT_PROVIDER = config.get("global","DEFAULT_PROVIDER") # save cache under dbroot self.CONF_CACHEDIR = os.path.join(dbroot,config.get("global","CACHE_DIRNAME")) self.CONF_MAX_DAY_EPG = config.getint("global","MAX_DAY_EPG") self.CONF_URL = config.get("global","URL") self.CONF_GMT_ZONE = config.get("global","GMT_ZONE") if self.CONF_GMT_ZONE.strip(' ').lower() == 'equal': #self.DELTA_UTC = -scriptlib.delta_utc() # return negative if timezone is east of GMT (like Italy), invert sign self.DELTA_UTC = 0 else: self.DELTA_UTC = float(self.CONF_GMT_ZONE) * 3600.0 if self.DELTA_UTC >= 0: self.DELTA_UTC = self.DELTA_UTC + scriptlib.delta_dst() else: self.DELTA_UTC = self.DELTA_UTC - scriptlib.delta_dst() self.DELTA_UTC = int(self.DELTA_UTC) #self.log("Website timezone - UTC = %d seconds" % self.DELTA_UTC) if not os.path.exists(self.CONF_CACHEDIR): self.log.log("Creating \'%s\' directory for caching" % self.CONF_CACHEDIR) os.mkdir(self.CONF_CACHEDIR) # reading [channels] section temp = config.items("channels"); # create a dictionary (Python array) with index = channel ID for i in temp: self.CHANNELLIST[i[0]] = unicode(i[1],'utf-8') if len(self.CHANNELLIST) == 0 : self.log.log("ERROR: [channels] section empty ?") sys.exit(1) # set network socket timeout socket.setdefaulttimeout(self.CONF_SOCKET_TIMEOUT) # initialize random generator random.seed() # today date (format AAAAMMDD) self.TODAY = time.strftime("%Y%m%d") # create a list filled with dates (format AAAAMMDD) from today to today+MAX_DAY_EPG self.DAYCACHE=[self.TODAY] for day in range(1,self.CONF_MAX_DAY_EPG): self.DAYCACHE.append(time.strftime("%Y%m%d",time.localtime(time.time()+86400*day)))
def __init__(self, confdir, dbroot): # initialize logging self.logging = scriptlib.logging_class() # write to video OSD the script name self.logging.log2video_scriptname(self.CONF_LOG_SCRIPT_NAME) # check swap memory available osp = os.popen('free | awk \'/Swap/ { print $2 }\'', 'r') ret = osp.readlines() if len(ret) > 0: try: m = int(ret[0]) / 1024 except: self.log("Error get SWAP value, abort", 1) time.sleep(10) sys.exit(1) if m < 60: self.log("SWAP Not Enabled (<60MB), abort", 1) time.sleep(10) sys.exit(1) else: self.log("Error get SWAP value, abort", 1) time.sleep(10) sys.exit(1) osp.close() CONF_FILE = os.path.join(confdir, self.CONF_CONFIGFILENAME) if not os.path.exists(CONF_FILE): self.log("ERROR: %s not present" % CONF_FILE, 1) sys.exit(1) config = ConfigParser.ConfigParser() #config.optionxform = str # needed to return case sensitive index config.read(CONF_FILE) # reading [global] section options self.CONF_DEFAULT_PROVIDER = config.get("global", "DEFAULT_PROVIDER") # save cache under dbroot self.CONF_CACHEDIR = os.path.join( dbroot, config.get("global", "CACHE_DIRNAME")) self.CONF_DL_DESC = config.getint("global", "DL_DESC") self.CONF_MAX_DAY_EPG = config.getint("global", "MAX_DAY_EPG") self.CONF_URL = config.get("global", "URL") self.CONF_GMT_ZONE = config.get("global", "GMT_ZONE") if self.CONF_GMT_ZONE.strip(' ').lower() == 'equal': #self.DELTA_UTC = -scriptlib.delta_utc() # return negative if timezone is east of GMT (like Italy), invert sign self.DELTA_UTC = 0 else: self.DELTA_UTC = float(self.CONF_GMT_ZONE) * 3600.0 if self.DELTA_UTC >= 0: self.DELTA_UTC = self.DELTA_UTC + scriptlib.delta_dst() else: self.DELTA_UTC = self.DELTA_UTC - scriptlib.delta_dst() self.DELTA_UTC = int(self.DELTA_UTC) #self.log("Website timezone - UTC = %d seconds" % self.DELTA_UTC) if not os.path.exists(self.CONF_CACHEDIR): self.log("Creating \'%s\' directory for caching" % self.CONF_CACHEDIR) os.mkdir(self.CONF_CACHEDIR) # reading [channels] section temp = config.items("channels") # create a dictionary (Python array) with index = channel ID for i in temp: self.CHANNELLIST[i[0].strip(' \n\r').lower()] = unicode( i[1].strip(' \n\r').lower(), 'utf-8') if len(self.CHANNELLIST) == 0: self.log("ERROR: [channels] section empty ?", 1) sys.exit(1) # set network socket timeout socket.setdefaulttimeout(self.CONF_SOCKET_TIMEOUT) self.TODAYMP = time.strftime("%Y/%m/%d") # create a list filled with dates (format AAAA/MM/DD) from today to today+ MAX_DAY_EPG self.DAYCACHEMP = [self.TODAYMP] for day in range(1, self.CONF_MAX_DAY_EPG): self.DAYCACHEMP.append( time.strftime("%Y/%m/%d", time.localtime(time.time() + 86400 * day)))
def __init__(self, confdir, dbroot): # initialize SGMLLIB sgmllib.SGMLParser.__init__(self, 0) # initialize logging class self.log = scriptlib.logging_class(self.CONF_LOG_FILENAME) # write to video OSD the script name self.log.log2video_scriptname(self.CONF_LOG_SCRIPT_NAME) self.log.log("=== RUNNING SCRIPT %s ===" % self.CONF_LOG_SCRIPT_NAME) CONF_FILE = os.path.join(confdir, self.CONF_CONFIGFILENAME) if not os.path.exists(CONF_FILE): self.log.log("ERROR: %s not present" % CONF_FILE) self.log.log2video_status("ERROR: %s not present" % CONF_FILE) sys.exit(1) config = ConfigParser.ConfigParser() #config.optionxform = str # needed to return case sensitive index config.read(CONF_FILE) # reading [global] section options self.CONF_DEFAULT_PROVIDER = config.get("global", "DEFAULT_PROVIDER") # save cache under dbroot self.CONF_CACHEDIR = os.path.join( dbroot, config.get("global", "CACHE_DIRNAME")) self.CONF_MAX_DAY_EPG = config.getint("global", "MAX_DAY_EPG") self.CONF_URL = config.get("global", "URL") self.CONF_GMT_ZONE = config.get("global", "GMT_ZONE") if self.CONF_GMT_ZONE.strip(' ').lower() == 'equal': #self.DELTA_UTC = -scriptlib.delta_utc() # return negative if timezone is east of GMT (like Italy), invert sign self.DELTA_UTC = 0 else: self.DELTA_UTC = float(self.CONF_GMT_ZONE) * 3600.0 if self.DELTA_UTC >= 0: self.DELTA_UTC = self.DELTA_UTC + scriptlib.delta_dst() else: self.DELTA_UTC = self.DELTA_UTC - scriptlib.delta_dst() self.DELTA_UTC = int(self.DELTA_UTC) #self.log.log("Website timezone - UTC = %d seconds" % self.DELTA_UTC) if not os.path.exists(self.CONF_CACHEDIR): self.log.log("Create \'%s\' directory for caching" % self.CONF_CACHEDIR) os.mkdir(self.CONF_CACHEDIR) # reading [channels] section temp = config.items("channels") # create a dictionary (Python array) with index = channel ID for i in temp: self.CHANNELLIST[i[0].strip(' \n\r').lower()] = unicode( i[1].strip(' \n\r').lower(), 'utf-8') if len(self.CHANNELLIST) == 0: self.log.log("ERROR: [channels] section empty ?") sys.exit(1) # set network socket timeout socket.setdefaulttimeout(self.CONF_SOCKET_TIMEOUT) self.TODAYMP = time.strftime("%d/%m/%Y") # create a list filled with dates (format DD/MM/AAAA) from today to today+ MAX_DAY_EPG self.DAYCACHEMP = [] for day in range(0, self.CONF_MAX_DAY_EPG): self.DAYCACHEMP.append( time.strftime("%d/%m/%Y", time.localtime(time.time() + 86400 * day)))
def __init__(self,confdir,dbroot): # initialize logging self.logging = scriptlib.logging_class() # write to video OSD the script name self.logging.log2video_scriptname(self.CONF_LOG_SCRIPT_NAME) # check swap memory available osp = os.popen('free | awk \'/Swap/ { print $2 }\'','r') ret = osp.readlines() if len(ret) > 0: try: m = int(ret[0])/1024 except: self.log("Error get SWAP value, abort",1) time.sleep(10) sys.exit(1) if m < 60: self.log("SWAP Not Enabled (<60MB), abort",1) time.sleep(10) sys.exit(1) else: self.log("Error get SWAP value, abort",1) time.sleep(10) sys.exit(1) osp.close() CONF_FILE = os.path.join(confdir,self.CONF_CONFIGFILENAME) if not os.path.exists(CONF_FILE) : self.log("ERROR: %s not present" % CONF_FILE,1) sys.exit(1) config = ConfigParser.ConfigParser() #config.optionxform = str # needed to return case sensitive index config.read(CONF_FILE) # reading [global] section options self.CONF_DEFAULT_PROVIDER = config.get("global","DEFAULT_PROVIDER") # save cache under dbroot self.CONF_CACHEDIR = os.path.join(dbroot,config.get("global","CACHE_DIRNAME")) self.CONF_DL_DESC = config.getint("global","DL_DESC") self.CONF_MAX_DAY_EPG = config.getint("global","MAX_DAY_EPG") self.CONF_URL = config.get("global","URL") self.CONF_GMT_ZONE = config.get("global","GMT_ZONE") if self.CONF_GMT_ZONE.strip(' ').lower() == 'equal': #self.DELTA_UTC = -scriptlib.delta_utc() # return negative if timezone is east of GMT (like Italy), invert sign self.DELTA_UTC = 0 else: self.DELTA_UTC = float(self.CONF_GMT_ZONE)*3600.0 if self.DELTA_UTC >= 0: self.DELTA_UTC = self.DELTA_UTC + scriptlib.delta_dst() else: self.DELTA_UTC = self.DELTA_UTC - scriptlib.delta_dst() self.DELTA_UTC = int(self.DELTA_UTC) #self.log("Website timezone - UTC = %d seconds" % self.DELTA_UTC) if not os.path.exists(self.CONF_CACHEDIR): self.log("Creating \'%s\' directory for caching" % self.CONF_CACHEDIR) os.mkdir(self.CONF_CACHEDIR) # reading [channels] section temp = config.items("channels"); # create a dictionary (Python array) with index = channel ID for i in temp: self.CHANNELLIST[i[0].strip(' \n\r').lower()] = unicode(i[1].strip(' \n\r').lower(),'utf-8') if len(self.CHANNELLIST) == 0 : self.log("ERROR: [channels] section empty ?",1) sys.exit(1) # set network socket timeout socket.setdefaulttimeout(self.CONF_SOCKET_TIMEOUT) self.TODAYMP = time.strftime("%Y/%m/%d") # create a list filled with dates (format AAAA/MM/DD) from today to today+ MAX_DAY_EPG self.DAYCACHEMP=[self.TODAYMP] for day in range(1,self.CONF_MAX_DAY_EPG): self.DAYCACHEMP.append(time.strftime("%Y/%m/%d",time.localtime(time.time()+86400*day)))