def create_apps(book_id):
    """
    Celery queued task that creates tt_apps and tt1 tasks

    :arg book_id: Internet archive book id
    :returns: book indicating if the applications were created
    :rtype: bool

    """

    try:
        imgs = meb_util.get_tt_images(book_id)
        bookInfo = meb_util.get_archive_book_data(book_id)
        
        app_tt_select = Apptt_select(short_name=book_id + "_tt1", title=bookInfo['title'], book_info=bookInfo)
        app_tt_meta = Apptt_meta(short_name=book_id + "_tt2", title=bookInfo['title'])
        app_tt_struct = Apptt_struct(short_name=book_id + "_tt3", title=bookInfo['title'])
        app_tt_transcribe = Apptt_transcribe(short_name=book_id + "_tt4", title=bookInfo['title'])
        
        app_tt_select.add_app_infos(bookInfo)
        app_tt_meta.add_app_infos(bookInfo)
        app_tt_struct.add_app_infos(bookInfo)
        app_tt_transcribe.add_app_infos(bookInfo)
        
        if len(app_tt_select.get_tasks()) == 0:
            for img in imgs:
                task = app_tt_select.add_task(img)
                workflow_transaction_info = dict(task_id_1=task.id, task_id_2=None, task_id_3=None, task_id_4=None)
                data_mngr.record_workflow_transaction(workflow_transaction_info)

        return True

    except Exception as e:
        return False
def close_t1(book_id):
    """
    Celery queued task that set's pybossa task type 1 (selection) 
    state to completed and close it. This function is is useful into case 
    that the book has only pages with tables.

    :arg task_id: Integer pybossa task id

    """
    
    tt_select = Apptt_select(short_name=book_id + "_tt1")
    tasks = tt_select.get_tasks()
    
    for task in tasks:
        tt_task = task_factory.get_task(task.id)
        tt_task.special_close_task()
        tt_task.add_next_task()