Ejemplo n.º 1
0
def close_ticket(task_id: int = None):
    """Close ticket."""
    wrapper = config.setup_api()
    if task_id is None:
        task_id = get_latest_ticket_id(wrapper)

    close_ticket(task_id)
Ejemplo n.º 2
0
def do_declare(uv: str, slot: str, content: str, declaration: str):
    """Declare work."""
    wrapper = config.setup_api()
    uv_id = get_uv_id(wrapper, uv)
    if uv_id == -1:
        print("UV is not available for declaration")
        return
    if slot is None:
        slot = find_current_slot()
        if slot is None:
            print("no slot available for declaring")
            print("please specify a slot with -s")
            return

    print("declaring for {} ({})".format(uv, uv_id))
    print("declaration slot : {}".format(slot))

    if content is None and declaration is None:
        content = ask_content()
    elif content is not None and declaration is not None:
        print("you can't choose both content and declaration")
        return
    elif declaration is not None:
        content = open(declaration).read()
    else:
        pass
    payload = {}
    payload['module'] = uv_id
    payload['declaration'] = {}
    payload['declaration']['start'] = slot.split(',')[0]
    payload['declaration']['end'] = slot.split(',')[1]
    payload['declaration']['content'] = content
    wrapper.declare_log(uv_id, payload)
Ejemplo n.º 3
0
def list(details: bool = False):
    """List tickets."""
    wrapper = config.setup_api()
    tickets = wrapper.get_tickets()
    if details:
        header = ("id", "title", "created at", "updated at", "closed at",
                  "login", "last edit", "last author")
    else:
        header = ("id", "title", "created by", "last edit", "last author")
    final_list = []
    for ticket in tickets['data']:
        ticket_list = []
        ticket_list.append(ticket['id'])
        ticket_list.append(ticket['title'])
        if details:
            ticket_list.append(ticket['created_at'])
            ticket_list.append(ticket['updated_at'])
            ticket_list.append(ticket['closed_at'])
        ticket_list.append(ticket['creator']['login'])
        ticket_list.append(ticket['last_edit']['login'])
        ticket_list.append(ticket['last_author']['login'])
        final_list.append(ticket_list)

    pretty_list = prettify_lists(final_list)
    print(tabulate(pretty_list, headers=header, tablefmt="simple"))
Ejemplo n.º 4
0
def grab_conversations(student: str = None,
                       latest: bool = False,
                       start: int = None,
                       count: int = None):
    wrapper = config.setup_api()
    user_id = wrapper.get_user_info(student)['id']

    convo_data = wrapper.get_conversations(user_id=user_id,
                                           start=start,
                                           size=count)
    for conv in convo_data['hits']:
        date = conv['created_at'].split('T')[0]
        time = conv['created_at'].split('T')[1].split('+')[0]
        likes, dislikes = get_likes(conv['last_message']['likes'])

        print("==============================")
        print("created on {} at {}".format(date, time))
        print("Wall : {}".format(conv['metas']['wall-name']))
        print("Title : {}".format(conv['title']))
        print(conv['last_message']['content'])
        print("views : {}".format(len(conv['last_message']['views'])))
        print("likes : {}   dislikes : {}".format(likes, dislikes))

        if latest is True:
            return
Ejemplo n.º 5
0
def add():
    """
    Add projects and quests to Task Warrior.
    """
    if TASK_INSTALLED is False:
        print("TaskWarrior is not installed.")
        print("Please install it to use this command")
        return

    wrapper = config.setup_api()
    data = wrapper.get_current_activities()

    for module in data.keys():
        for i in range(len(data[module]['project'])):
            print(data[module]['project'][i]['name'], ":", module)
            add_data_to_taskw(data[module]['project'][i], module, None)

        stage_nb = 0
        for i in range(len(data[module]['quest'])):
            for stage in data[module]['quest'][i]['stages']:
                quest = data[module]['quest'][i]['name']
                print("{0} - {1}:{2}".format(module, quest, stage['name']))
                add_data_to_taskw(stage, module, quest)
                stage_nb += 1

            if stage_nb == 0:
                print(data[module]['quest'][i]['name'], module)
                add_data_to_taskw(data[module]['quest'][i], module, None)
Ejemplo n.º 6
0
def show(task_id: int = None):
    """Show content of ticket."""
    wrapper = config.setup_api()
    if task_id is None:
        task_id = get_latest_ticket_id(wrapper)
    ticket = wrapper.get_ticket(task_id)

    data = ticket['data']
    print("id            : {}".format(data['id']))
    print("title         : {}".format(data['title']))
    print("ttl           : {}".format(data['ttl']))
    print("created at    : {}".format(data['created_at']))
    print("updated at    : {}".format(data['updated_at']))
    print("closed at     : {}".format(data['closed_at']))
    print("creator       : {}".format(data['creator']['login']))
    print("users         : ", end="")
    [print(user['login'], end=" ") for user in data['users']]
    print(end="\n")
    print_view_order(data['views'])

    for message in data['messages']:
        print("========================")
        print("{} | {} :".format(message['created_at'],
                                 message['author']['login']))
        print(message['content'])
Ejemplo n.º 7
0
def activites(type_: str = None):
    """List activites."""
    wrapper = config.setup_api()
    projects = wrapper.get_projects()

    for project in projects:
        pid = project['id']
        activites = wrapper.get_project_activites(pid)
        handle_activites(activites, type_)
Ejemplo n.º 8
0
def get_begining_of_run() -> datetime:
    """Get the begining of a run to list available modules."""
    wrapper = config.setup_api()
    logs = wrapper.get_logs()
    if len(logs['contracts'][0]['periods']) == 0:
        return None
    start = logs['contracts'][0]['periods'][0]['start'].split()[0]
    start_run = datetime.strptime(start.split()[0], '%Y-%m-%d') \
        + timedelta(days=1)
    return start_run
Ejemplo n.º 9
0
def create_ticket(title: str, content: str, tags: str, students: str = None):
    """Create ticket."""
    wrapper = config.setup_api()

    tag_list = tags.split(',')
    if students:
        student_list = students.split(',')
    else:
        student_list = None
    wrapper.open_ticket(title, content, tag_list, student_list)
Ejemplo n.º 10
0
def list():
    """List projects."""
    wrapper = config.setup_api()
    projects = wrapper.get_projects()
    final_list = []
    header = ('Name', 'UV', 'starts at', 'ends on', 'Time', 'Validated')
    for project in projects:
        project_list = []
        project_list.append(project['long_name'])
        project_list.append(project['uv_name'])
        project_list.append(project['date_start'])
        project_list.append(project['date_end'])
        project_list.append(f"{int(project['duration']) / 3600} hours")
        project_list.append(is_validated(project['validation']))
        final_list.append(project_list)
    print_table(final_list, header)
Ejemplo n.º 11
0
def promo(student: str = None):
    """Get student's promotions."""
    wrapper = config.setup_api()
    promo_data = wrapper.get_user_promotion(student)
    header = ('ID', 'promotion', 'name', 'start', 'end', 'spe')
    final_list = []
    for i, _ in enumerate(promo_data):
        promo_list = []
        promo_list.append(promo_data[i]['id'])
        promo_list.append(promo_data[i]['promo'])
        promo_list.append(promo_data[i]['wall_name'])
        promo_list.append(promo_data[i]['learning_start'])
        promo_list.append(promo_data[i]['learning_end'])
        promo_list.append(promo_data[i]['spe'])
        final_list.append(promo_list)

    print_table(final_list, header)
Ejemplo n.º 12
0
def info(student: str = None):
    """Get student's info."""
    wrapper = config.setup_api()
    user_data = wrapper.get_user_info(student)

    if "not found" in user_data:
        print("user not found")
        return

    for i in user_data.keys():
        # older users have roles instead of groups
        if i in ("roles", "groups"):
            print("groups : ", end="")
            [print(group, end=" ") for group in user_data[i]]
            print(end="\n")
        else:
            print("{} : {}".format(i, user_data[i]))
Ejemplo n.º 13
0
def list(student: str = None, time: str = None):
    """List events."""
    wrapper = config.setup_api()
    events_data = get_events(wrapper, student, time)
    header = ('name', 'UV name', 'activity', 'location', 'start', 'ends')
    final_list = []
    for event in events_data:
        event_list = []
        event_list.append(event['name'])
        event_list.append(event['uv_name'])
        event_list.append(event['activity_name'])
        event_list.append(event['location'])
        event_list.append(event['start'])
        event_list.append(event['end'])
        final_list.append(event_list)

    print_table(final_list, header)
Ejemplo n.º 14
0
def grades(student: str = None, promo: int = None, activity: str = None):
    """Get student's grades."""
    wrapper = config.setup_api()
    if promo is None:
        promo = wrapper.get_user_promotion(student)[0]['id']
    grades_data = wrapper.get_grades(login=student, promotion_id=promo)
    header = ('activity', 'type', "UV name", 'mark', 'average', 'max', 'min')
    final_list = []

    for mark in grades_data:
        mark_list = []
        mark_list.append(mark['activity_name'])
        mark_list.append(mark['activity_type'])
        mark_list.append(mark['uv_name'])
        mark_list.append(mark['student_mark'])
        mark_list.append(roundify(mark['average']))
        mark_list.append(mark['maximal'])
        mark_list.append(mark['minimal'])
        final_list.append(mark_list)

    print_table(final_list, header)
Ejemplo n.º 15
0
def print_available_modules():
    """List available modules to declare for."""
    wrapper = config.setup_api()
    start_run = get_begining_of_run()
    if start_run is None:
        start_run = date.today()
    projects = wrapper.get_projects(date=start_run)
    final_list = []
    header = ("ID", "name", "UV", "start", "end", "duration")
    for project in projects:
        project_list = []
        if project['duration'] != 0:
            project_list.append(project['id'])
            project_list.append(project['long_name'])
            project_list.append(project['uv_name'])
            project_list.append(project['date_start'])
            project_list.append(project['date_end'])
            project_list.append(f"{int(project['duration']) / 3600} hours")
            final_list.append(project_list)
        else:
            pass
    print_table(final_list, header)
Ejemplo n.º 16
0
def list_declarations(number: int):
    """List declarations."""
    wrapper = config.setup_api()
    declarations = wrapper.get_declarations()
    cnt = 0
    final_list = []
    header = ('UV', 'start', 'end', 'description', "declared at")
    for declaration in declarations['hits']:
        declare_list = []
        start = declaration['start'].replace('T', ' ').split('+')[0]
        end = declaration['end'].replace('T', ' ').split('+')[0]
        declare_list.append(declaration['uv_name'])
        declare_list.append(start)
        declare_list.append(end)
        declare_list.append(declaration['metas']['description'])
        declare_list.append(declaration['metas']['declared_at'])
        final_list.append(declare_list)
        cnt += 1
        if number is not None and cnt == number:
            break

    print_table(final_list, header, fmt='fancy_grid', prettify=False)
Ejemplo n.º 17
0
def get_student_rank(student: str = None,
                     promo: str = None,
                     activity: str = None):
    """Get student rank."""
    wrapper = config.setup_api()

    if promo is None and student is None:
        student_info = wrapper.get_user_info()
        login = student_info['login']
        promo = wrapper.get_user_promotion(login)[0]['id']
    elif student is not None and promo is None:
        promo = wrapper.get_user_promotion(student)[0]['id']
    elif student is None and promo is not None:
        student_info = wrapper.get_user_info()
        login = student_info['login']
    else:
        return

    promo_list = get_students_by_promo(wrapper, int(promo))
    if promo_list is None:
        return

    student_marks = {}

    for student in promo_list:
        print(f"grabing grades for {student}", end='\r')
        student_grades = wrapper.get_grades(login=student, promotion_id=promo)

        student_marks[student] = 0
        cnt = 0

        for student_grade in student_grades:
            if activity is not None:
                if activity == student_grade['activity_name']:
                    student_marks[student] = student_grade['student_mark']
                    cnt = 1
                    break
            else:
                # Some users have 'Null' instead of a real mark
                if student_grade['student_mark'] is not None:
                    student_marks[student] += int(
                        student_grade['student_mark'])
                    cnt += 1
                else:
                    pass
    sorted_students = sorted(student_marks.items(),
                             key=operator.itemgetter(1),
                             reverse=True)

    header = ('rank', 'student', 'average')
    final_list = []
    for i in range(0, len(sorted_students)):
        student_list = []
        try:
            average = sorted_students[i][1] / cnt
        except ZeroDivisionError:
            average = 0
        student_list.append(i + 1)
        student_list.append(sorted_students[i][0])
        student_list.append(round(average, 2))
        final_list.append(student_list)
    print_table(final_list, header)
Ejemplo n.º 18
0
def get_declaration_schedule() -> dict:
    wrapper = config.setup_api()
    logs = wrapper.get_logs()
    # there could me multipe contracts.
    # at this point just use the last one
    return logs['contracts'][0]['schedules']