Beispiel #1
0
def main(file):
    app.app_context().push()

    user = User.get_by_id(USER_ID)
    if not user:
        raise Exception(f"User with id '{USER_ID}' not found!")
    logging.info("Fetched user: %s", user)

    expenditures = get_expenditures()
    save_expenditures_to_csv(expenditures, file)
Beispiel #2
0
def witness_services(func, utc_date_time):
    with app.app_context():
        if func == 'make_witness_schedule':
            operations.make_witness_schedule(utc_date_time, index=None)
        elif func == 'make_witness_schedule_period':
            operations.make_witness_schedule_period(utc_date_time, index="1")
        elif func == 'witness_miss_block_by_day':
            logging.info(
                operations.witness_miss_block_by_day(utc_date_time,
                                                     index=None))
        elif func == 'witness_miss_block_by_period':
            logging.info(
                operations.witness_miss_block_by_day(utc_date_time, index="1"))
Beispiel #3
0
def main(file):
    app.app_context().push()

    user = User.get_by_id(USER_ID)
    if not user:
        raise Exception(f"User with id '{USER_ID}' not found!")
    logging.info("Fetched user: %s", user)
    nr_of_user_expenditures_start = user.expenditures.count()

    create_main_categories()
    create_sub_categories()

    basic_expenditures = read_expenditures_from_csv(file)
    db_expenditures = translate_basic_to_db_expenditures(basic_expenditures)

    save_db_expenditures_to_db(db_expenditures)

    nr_of_user_expenditures_end = user.expenditures.count()
    logging.info("User expenditures at the beelining: %d",
                 nr_of_user_expenditures_start)
    logging.info("User expenditures at the end: %d",
                 nr_of_user_expenditures_end)
Beispiel #4
0
def main():
    print("Create Admin User")

    with app.app_context():
        print('USER NAME')
        user_name = raw_input()

        print('ENTER EMAIL')
        email = raw_input()

        print('ENTER PASSWORD')
        password = getpass()
        assert password == getpass('Password again:')

        user = User(user_name, email, password, is_admin=True)
        user.save()
Beispiel #5
0
def fire_programme_start(programme_id, **kwargs):
    import datetime
    from sweet_cms.models import Programme
    from libs.sweet_apps import get_sweet_app
    from autoapp import app
    import socketio
    with app.app_context():
        programme = Programme.query.filter_by(id=programme_id).first()
        if not programme:
            print("Programme Was deleted , stopping now")
            return
        if not app.config['DEBUG']:
            ws_url = "https://www.mediville.com"
            path = 'sockets/socket.io'
        else:
            ws_url = "http://127.0.0.1:5501"
            path = "socket.io"
        sio = socketio.Client()
        sio.connect(ws_url, socketio_path=path)
        sio.emit("programme_started", {
            "event_id": programme.event.id,
            "programme_id": programme.id
        })
        print("HI", datetime.datetime.now())
Beispiel #6
0
import logging
import datetime
from backend.block import operations
from scripts import block_service
from autoapp import app

taskname = "fetch block"
if __name__ == "__main__":

    try:
        current_time = datetime.datetime.now().timestamp()
        with app.app_context():
            head_block = operations.query_block_max()
            if head_block:
                delta = int(current_time) - 81 - head_block.timestamp
                delta_block_num = int(delta / 3)
                beginNumber = head_block.number + 1  # 当前头块的下一块
                endNumber = beginNumber + delta_block_num
                block_service.fetch_block(beginNumber, endNumber)
                logging.info(
                    'execute crontab [%s] success. head_block number: %d, beginNumber: %d, endNumber: %d',
                    taskname, head_block.number, beginNumber, endNumber)
    except Exception as e:
        logging.error('execute crontab [%s] error: %s', taskname, e)
Beispiel #7
0
def process_video(file_id, **kwargs):
    from sweet_cms.models import ProgrammeFile
    from libs.sweet_apps import get_sweet_app
    from autoapp import app
    import ffmpeg_streaming
    from ffmpeg_streaming import Formats
    import ffmpeg
    from shutil import copy
    from flask import url_for

    with app.app_context():
        eventy_app = get_sweet_app('Eventy')
        programme_file = ProgrammeFile.query.filter_by(id=file_id).first()
        if not programme_file:
            print("File Was deleted , stopping now")
            return
        file_path = programme_file.file_url
        app.config['SERVER_NAME'] = 'localhost'
        file_url = '/admin/eventy/uploads/programmes/{}/videos/'.format(
            programme_file.programme.id)
        file_path = os.path.join(eventy_app.app_path,
                                 app.config['EVENTY_UPLOADS_DIR'], file_path)
        print(file_id, programme_file, file_path, file_url)

        if os.path.exists(file_path):
            programme_file.file_status = 'processing'
            db.session.add(programme_file)
            db.session.commit()

            file_dir = os.path.dirname(file_path)
            file_name = os.path.basename(file_path)
            bare_file_name = '.'.join(file_name.split('.')[:-1])
            new_path = os.path.join(file_dir, bare_file_name + '.mp4')
            # data = ffmpeg.probe(file_path)
            input_video = ffmpeg.input(file_path)
            output_path = os.path.join('/tmp', bare_file_name + '.mp4')
            (ffmpeg.output(input_video,
                           output_path,
                           vcodec='libx264',
                           acodec='aac',
                           movflags='faststart').overwrite_output().run())
            copy(output_path, file_dir)
            # os.remove(output_path)
            if new_path != file_path:
                os.remove(file_path)
            # if "bit_rate" not in str(data):
            #     (
            #         ffmpeg
            #             .output(input_video, output_path, vcodec='copy', acodec='copy')
            #             .overwrite_output()
            #             .run()
            #     )
            #     copy(output_path, file_path)
            #     os.remove(output_path)
            # video = ffmpeg_streaming.input(file_path)
            # hls = video.hls(Formats.h264())
            # hls.auto_generate_representations()
            # hls.output(playlist_path)
            # m3u8_fix(playlist_path, file_url)
            data = ffmpeg.probe(new_path)
            programme_file.file_details = json.dumps(data)
            programme_file.file_status = 'ready'
            programme_file.file_name = bare_file_name + '.mp4'
            db.session.add(programme_file)
            db.session.commit()
            print("Done on : {}".format(str(file_path)))