def process_dates(npr_dates_to_fix, verbose=False): if verbose and len(npr_dates_to_fix) > 0: print "GOT %d dates to fix" % len(npr_dates_to_fix) time0 = time.time() for idx, mydate in enumerate(npr_dates_to_fix): freshair.get_freshair("/mnt/media/freshair", mydate) if verbose: print "PROCESSED %d / %d DATES IN %0.3f SECONDS" % (idx + 1, len(npr_dates_to_fix), time.time() - time0) if verbose and len(npr_dates_to_fix) > 0: print "PROCESSED ALL DATES IN %0.3f SECONDS" % (time.time() - time0)
def process_dates(npr_dates_to_fix, verbose=False): if verbose and len(npr_dates_to_fix) > 0: print 'GOT %d dates to fix' % len(npr_dates_to_fix) time0 = time.time() for idx, mydate in enumerate(npr_dates_to_fix): freshair.get_freshair('/mnt/media/freshair', mydate) if verbose: print 'PROCESSED %d / %d DATES IN %0.3f SECONDS' % ( idx + 1, len(npr_dates_to_fix), time.time() - time0) if verbose and len(npr_dates_to_fix) > 0: print 'PROCESSED ALL DATES IN %0.3f SECONDS' % (time.time() - time0)
def freshair_crontab(): """ This python module downloads a Fresh Air episode on a particular weekday """ # get current time current_date = datetime.date.fromtimestamp(time.time()) if not npr_utils.is_weekday( current_date ): print "Error, today is not a weekday. Instead, today is %s." % \ current_date.strftime('%A') return # now download the episode into the correct directory freshair.get_freshair('/mnt/media/freshair', current_date, check_if_exist = True)
def find_underoccupied_dates( mon, year = _default_year ): newdict = {} days = find_occupied_days( mon, year = year ) daydict = { day : os.path.join( _default_inputdir, 'NPR.FreshAir.%02d.%02d.%d.m4a' % ( day, mon, year ) ) for day in days } actdict = { day : EasyMP4( daydict[day] ).info.length for day in filter(lambda day: os.stat(daydict[day]).st_size <= 4e7, daydict) } # now get tree for each of these files for day in actdict: dt_s = datetime.datetime.strptime('%02d.%02d.%04d' % ( day, mon, year ), '%d.%m.%Y' ).date( ) tree = freshair.get_freshair( os.path.expanduser('~'), dt_s, debug = True, to_file_debug = False ) expectdur = 0 for elem in tree.iter('story'): durs = list( elem.iter('duration')) if len(durs) == 0: continue expectdur += int( max(elem.iter('duration')).text ) totlength = actdict[ day ] if expectdur == 0: newdict[day] = ( totlength, 1.0, get_color( 1.0 ) ) continue discrep = max(0.0, expectdur * 0.985 - totlength ) / ( 0.985 * expectdur ) if discrep <= 1e-6: continue newdict[day] = ( totlength, discrep, get_color( discrep ) ) return newdict
def freshair_crontab(): """ This python module downloads a Fresh Air episode on a particular weekday """ # get current time current_date = datetime.date.fromtimestamp(time.time()) if not npr_utils.is_weekday(current_date): print "Error, today is not a weekday. Instead, today is %s." % \ current_date.strftime('%A') return # now download the episode into the correct directory freshair.get_freshair('/mnt/media/freshair', current_date, check_if_exist=True)
def _process_freshair_perproc(mydate): try: fname = freshair.get_freshair('/mnt/media/freshair', mydate) if fname is None: return None return mydate except Exception as e: print(e) return None
def find_underoccupied_dates(mon, year=_default_year): newdict = {} days = find_occupied_days(mon, year=year) daydict = { day: os.path.join(_default_inputdir, 'NPR.FreshAir.%02d.%02d.%d.m4a' % (day, mon, year)) for day in days } actdict = { day: EasyMP4(daydict[day]).info.length for day in filter( lambda day: os.stat(daydict[day]).st_size <= 4e7 and EasyMP4( daydict[day]).info.length <= 35 * 60, daydict) } # now get tree for each of these files for day in actdict: dt_s = datetime.datetime.strptime('%02d.%02d.%04d' % (day, mon, year), '%d.%m.%Y').date() tree = freshair.get_freshair(os.path.expanduser('~'), dt_s, debug=True, to_file_debug=False) expectdur = 0 for elem in tree.iter('story'): durs = list(elem.iter('duration')) if len(durs) == 0: continue expectdur += int(max(elem.iter('duration')).text) totlength = actdict[day] if expectdur == 0: newdict[day] = (totlength, 1.0, get_color(1.0)) continue discrep = max(0.0, expectdur * 0.985 - totlength) / (0.985 * expectdur) if discrep <= 1e-6: continue newdict[day] = (totlength, discrep, get_color(discrep)) return newdict