Beispiel #1
0
 def _check_cmd_ignore(self, cmd, ignore_for, lastused_file):
     if not cmd:
         if lastused_file == self.PRE_LASTUSED_FILE:
             cmd_type = 'pre'
         else:
             cmd_type = 'post'
         self.LW.log(['no %s command to check' % cmd_type])
         return ''
     if ignore_for == 0:
         self.LW.log(['ignoring the cache time and running command'])
         return cmd
     if os.path.isfile(lastused_file):
         exists = True
         loglines, lastused = readFile(lastused_file)
         self.LW.log(loglines)
     else:
         exists = False
     if (not exists) or (time.time() - float(lastused) > ignore_for * 60):
         self.LW.log(['setting lastused and running command'])
         success, loglines = writeFile(str(time.time()),
                                       lastused_file,
                                       wtype='w')
         self.LW.log(loglines)
         return cmd
     self.LW.log(['ignoring command for now'])
     return ''
 def _get_data(self, filepath, cachefilepath, url, url_params):
     json_data = ''
     if self._update_cache(filepath, cachefilepath):
         success, uloglines, json_data = self.JSONURL.Get(url,
                                                          params=url_params)
         self.LOGLINES.extend(uloglines)
         if success:
             success, wloglines = writeFile(
                 py2_encode(_json.dumps(json_data)), filepath)
             self.LOGLINES.extend(wloglines)
     exists, cloglines = checkPath(filepath, False)
     self.LOGLINES.extend(cloglines)
     if exists:
         self._get_audiodbid(
         )  # this is to generate the id file if it doesn't exist
         rloglines, rawdata = readFile(filepath)
         self.LOGLINES.extend(rloglines)
         try:
             json_data = _json.loads(rawdata)
         except ValueError:
             success, dloglines = deleteFile(filepath)
             self.LOGLINES.extend(dloglines)
             self.LOGLINES.append(
                 'Deleted old cache file. New file will be download on next run.'
             )
             json_data = ''
     return json_data
 def _get_audiodbid(self):
     audiodbid = ''
     exists, cloglines = checkPath(self.IDFILEPATH, False)
     self.LOGLINES.extend(cloglines)
     if not exists:
         exists, cloglines = checkPath(self.ARTISTFILEPATH, False)
         self.LOGLINES.extend(cloglines)
         if exists:
             rloglines, rawdata = readFile(self.ARTISTFILEPATH)
             self.LOGLINES.extend(rloglines)
             try:
                 gotData = True
                 json_data = _json.loads(rawdata)
             except ValueError:
                 self.LOGLINES.append(
                     'no valid JSON data returned from theaudiodb.com, setting artist to None'
                 )
                 gotData = False
             if gotData:
                 artist = json_data.get('artists')
             else:
                 artist = None
             if artist is not None:
                 audiodbid = artist[0].get('idArtist', '')
             if audiodbid:
                 success, wloglines = writeFile(audiodbid, self.IDFILEPATH)
                 self.LOGLINES.extend(wloglines)
     rloglines, audiodbid = readFile(self.IDFILEPATH)
     self.LOGLINES.extend(rloglines)
     return audiodbid
Beispiel #4
0
 def _put_cache_time(self, cachefilepath):
     self.LOGLINES.append(
         'writing out the cache timeout information for last.fm')
     cachetime = random.randint(self.CACHEEXPIRE['low'],
                                self.CACHEEXPIRE['high'])
     success, wloglines = writeFile(str(cachetime), cachefilepath)
     self.LOGLINES.append(wloglines)
     return success
Beispiel #5
0
def _update_followed_cache( tvmcachefile, tvmazeapi, lw, showname='' ):
    if showname:
        _manage_followed( showname, 'follow', tvmazeapi, lw )
    success, loglines, results = tvmazeapi.getFollowedShows( params={'embed':'show'} )
    lw.log( loglines )
    if success:
        tvmcache = results
    else:
        lw.log( ['no valid response returned from TV Maze'] )
        tvmcache = []
    if tvmcache:
        success, loglines = writeFile( json.dumps( tvmcache ), tvmcachefile, wtype='w' )
        lw.log( loglines )
    return tvmcache
Beispiel #6
0
 def _get_data(self, filepath, cachefilepath, url_params):
     rawxml = ''
     if self._update_cache(filepath, cachefilepath):
         success, uloglines, data = self.TEXTURL.Get(self.URL,
                                                     params=url_params)
         self.LOGLINES.extend(uloglines)
         if success:
             success, wloglines = writeFile(py2_encode(data), filepath)
             self.LOGLINES.extend(wloglines)
     exists, cloglines = checkPath(filepath, False)
     self.LOGLINES.extend(cloglines)
     if exists:
         rloglines, rawxml = readFile(filepath)
         self.LOGLINES.extend(rloglines)
     return rawxml
Beispiel #7
0
 def _setPID(self):
     self.LW.log(['setting PID file'])
     try:
         last_pidfile = glob.glob(
             os.path.join(self.ROOTPATH, 'data', '*.pid'))[-1]
         loglines, prev_pid = readFile(last_pidfile)
         self.LW.log(loglines)
         pid = str(int(prev_pid) + 1)
         self.PREVPIDFILE = os.path.join(self.ROOTPATH, 'data',
                                         'iguana-blaster-%s.pid' % prev_pid)
     except IndexError:
         pid = '0'
         self.PREVPIDFILE = os.path.join(self.ROOTPATH, 'data', 'dummy.pid')
     global pidfile
     pidfile = os.path.join(self.ROOTPATH, 'data',
                            'iguana-blaster-%s.pid' % pid)
     success, loglines = writeFile(pid, pidfile, wtype='w')
     self.LW.log(loglines)
Beispiel #8
0
 def _update_episode_cache( self, epid=None, item=None, items=None ):
     loglines, episode_cache = readFile( self.EPISODECACHE )
     self.LW.log( loglines )
     cache_changed = True
     if episode_cache:
         epcache_json = json.loads( episode_cache )
     else:
         epcache_json = {}
     if epid:
         try:
             del epcache_json[str( epid )]
         except KeyError:
             cache_changed = False
     elif item:
         epcache_json[str( item['epid'] )] = item
     elif items:
         for item in items:
             epcache_json[str( item['epid'] )] = item
     if cache_changed:
         success, loglines = writeFile( json.dumps( epcache_json ), self.EPISODECACHE, 'w' )
         self.LW.log( loglines )
Beispiel #9
0
 def _put_cache_time(self, cachefilepath):
     cachetime = random.randint(self.CACHEEXPIRE.get(
         'low'), self.CACHEEXPIRE.get('high'))
     success, wloglines = writeFile(str(cachetime), cachefilepath)
     self.LOGLINES.append(wloglines)
     return success