def run_once(): try: Session = core.init_db() except OperationalError as e: print("数据库初始化失败: {}".format(e)) print("程序即将终止") exit() nv = core.extract_data() core.save(Session, nv)
def index(): # download url = request.params.text title, filename = download_song(url) print(f'Downloaded {url} - {title} - {filename}') # add to queue conn = init_db() add_song(conn, filename) conn.close() return f'Song "{title}" added to playlist\nTune in at http://157.230.40.19:8000/main.ogg'
def scan(): try: Session = core.init_db() except OperationalError as e: print("数据库初始化失败: {}".format(e)) print("程序即将终止") exit() data = core.scan() for i in data: value, date_str = i['value'], i['date'] date = datetime.strptime(date_str, '%Y-%m-%d').date() core.save(Session, value, date)
def main(): try: Session = core.init_db() except OperationalError as e: print("数据库初始化失败: {}".format(e)) print("程序即将终止") exit() frequency = is_every_n_minutes(5) while True: current = datetime.now() if frequency(current): nv = core.extract_data() if nv is not None: core.save(Session, nv) sys.stdout.flush() sleep(30)
#!/usr/bin/env python3 from core import init_db, pop_song if __name__ == "__main__": conn = init_db() next_filename = pop_song(conn) conn.close() print(f'{next_filename}')