Example #1
0
def main():
    username = shared.get_git_variables()['username']
    url = shared.get_git_variables()['url']
    split_days = metadata.split_on_days(gtc.get_all_as_dict())
    t_string = '\n'
    t_string += (username + ' worked on project ' + url.split('/')[4])
    t_string += ('\nurl: ' + url + '\n')
    t_string += table_print(split_days)
    print(t_string)
Example #2
0
    def post(self):
        try:
            json_data = request.get_json(force=True)
            issue = json_data['issue']
            start_time = json_data['start_time']
            end_time = json_data['end_time']
            username = json_data['username']
            # data = {}
            # data['info'] = {'issue': issue, 'start_time': start_time,
            # 'end_time': end_time, 'username': username}
            shared.set_issue_number(issue)
            tz = metadata.get_tz_info()
            start_time = metadata.convert_from_js(start_time, tz)
            end_time = metadata.convert_from_js(end_time, tz)
            start_time += ':00' + tz
            end_time += ':00' + tz
            issuenumber = shared.get_issue_number()

            note_dict = {}
            note_dict = {
                'user': shared.get_git_variables()['username'],
                'timestamp_start': start_time,
                'timestamp_end': end_time,
                'issue': issuenumber
            }
            gtc.store(target=[
                shared.get_git_variables()['username'],
                datetime.now().year,
                datetime.now().month
            ],
                      content=note_dict)
            newdata = {}
            newdata['split_days'] = metadata.split_on_days(
                gtc.get_all_by_path([
                    shared.get_git_variables()['username'],
                    datetime.now().year,
                    datetime.now().month
                ]))
            return jsonify(status="Succes", newdata=newdata)
        except:
            print('CRASH!')
            newdata['split_days'] = metadata.split_on_days(
                gtc.get_all_by_path([
                    shared.get_git_variables()['username'],
                    datetime.now().year,
                    datetime.now().month
                ]))
            return jsonify(status="Failed", data=newdata)
Example #3
0
 def post(self):
     json_data = request.get_json(force=True)
     sha1 = json_data['sha1']
     gtc.store(target=[
         shared.get_git_variables()['username'],
         datetime.now().year,
         datetime.now().month
     ],
               remove=sha1)
     newdata = {}
     newdata['split_days'] = metadata.split_on_days(
         gtc.get_all_by_path([
             shared.get_git_variables()['username'],
             datetime.now().year,
             datetime.now().month
         ]))
     return jsonify(newdata=newdata)
Example #4
0
 def get(self):
     newdata = {}
     newdata['split_days'] = metadata.split_on_days(
         gtc.get_all_by_path([
             shared.get_git_variables()['username'],
             datetime.now().year,
             datetime.now().month
         ]))
     return jsonify(newdata=newdata)
Example #5
0
def _write_note(note_dict, value, state, **kwargs):
    logging.debug(f'timelog._write_note({note_dict}, {value}, {kwargs})')
    cday = kwargs.get('cday', None)
    if value is not None:
        chour, cminute = _split_time_value(value)
        if cday is not None:
            if state == 'start':
                note_dict['timestamp_start'] = metadata.time(chour=chour,
                                                             cminute=cminute,
                                                             cday=cday)
            else:
                note_dict['timestamp_end'] = metadata.time(chour=chour,
                                                           cminute=cminute,
                                                           cday=cday)
        else:
            if state == 'start':
                note_dict['timestamp_start'] = metadata.time(chour=chour,
                                                             cminute=cminute)
            else:
                note_dict['timestamp_end'] = metadata.time(chour=chour,
                                                           cminute=cminute)
    else:
        if state == 'start':
            note_dict['timestamp_start'] = metadata.time()
        elif state == 'end':
            note_dict['timestamp_end'] = metadata.time()
    if state == 'start':
        gtc.store(target=[
            shared.get_git_variables()['username'],
            datetime.now().year,
            datetime.now().month
        ],
                  content=note_dict)  # Tilfoej ny!
        # gtc.store(target=[shared.get_git_variables()['username'], datetime.now().year, datetime.now().month], remove='74866fd4078fdad62b13a4968087852aec7b0788')
    elif state == 'end':
        gtc.store(target=[
            shared.get_git_variables()['username'],
            datetime.now().year,
            datetime.now().month
        ],
                  append='sha1',
                  content={'timestamp_end': '123'})  # tilfoej s**t tid
    return note_dict
Example #6
0
    def put(self):
        try:
            json_data = request.get_json(force=True)
            sha1 = json_data['sha1']
            newissue = json_data['issue']
            timestamp_start = json_data['start_time']
            timestamp_end = json_data['end_time']
            tz = metadata.get_tz_info()
            og = gtc.get_all_by_path([
                shared.get_git_variables()['username'],
                datetime.now().year,
                datetime.now().month
            ])[sha1]
            try:
                issue = og['issue']
            except:
                issue = None
            try:
                if int(issue) != int(newissue):
                    issue = newissue
            except:
                issue = newissue
            timestamp_start = metadata.convert_from_js(timestamp_start, tz)
            timestamp_end = metadata.convert_from_js(timestamp_end, tz)
            if datetime.strptime(timestamp_start,
                                 '%Y-%m-%dT%H:%M') <= datetime.strptime(
                                     timestamp_end, '%Y-%m-%dT%H:%M'):
                time = timestamp_start[11:]
                datestamp = timestamp_start[:10]
                month = datestamp[5:-3]
                date = datestamp[-2:]
                hour = time[:2]
                minute = time[-2:]
                timestamp_start = metadata.time(chour=hour,
                                                cminute=minute,
                                                cday=date,
                                                cmonth=month)
                time = timestamp_end[11:]
                datestamp = timestamp_end[:10]
                month = datestamp[5:-3]
                date = datestamp[-2:]
                hour = time[:2]
                minute = time[-2:]
                timestamp_end = metadata.time(chour=hour,
                                              cminute=minute,
                                              cday=date,
                                              cmonth=month)

            gtc.store(target=[
                shared.get_git_variables()['username'],
                datetime.now().year,
                datetime.now().month
            ],
                      remove=sha1,
                      content={
                          'timestamp_end': timestamp_end,
                          'timestamp_start': timestamp_start,
                          'issue': issue,
                          'user': shared.get_git_variables()['username']
                      })

            newdata = {}
            newdata['split_days'] = metadata.split_on_days(
                gtc.get_all_by_path([
                    shared.get_git_variables()['username'],
                    datetime.now().year,
                    datetime.now().month
                ]))
            return jsonify(status="Succes", newdata=newdata)
        except:
            print('CRASH!')
            newdata = {}
            newdata['split_days'] = metadata.split_on_days(
                gtc.get_all_by_path([
                    shared.get_git_variables()['username'],
                    datetime.now().year,
                    datetime.now().month
                ]))
            return jsonify(status="Failed", data=newdata)
Example #7
0
 def test_git_variables(self):
     result = shared.get_git_variables()
     expected = 'https://www.github.com/prolike/timereg'
     self.assertEqual(result['url'], expected)
Example #8
0
def log_type(state, **kwargs):
    logging.debug(f'timelog.log_type({state}, {kwargs})')
    '''
    Makes our meta data string, that we are gonna use for logging time in git notes.

    Args:
        param1(str): state - if you 'start' the time log or 'end' it
        param2(str): chour - custom hour for the time returned
        param3(str): cminute - custom minute for the time returned

    Return:
        str: Returns a string with meta data including, git username, state (start or end),
        and timestamp with date (from the time method)
    '''
    value = kwargs.get('value', None)
    cday = kwargs.get('date', None)
    username = shared.get_git_variables()['username']
    note_dict = {}
    note_dict['user'] = username
    note_dict['issue'] = shared.get_issue_number()
    # print(state)
    # if metadata.check_correct_order(username, state) is True:
    #     try:
    #         if cday is None:
    #             return _state_types(state, value, note_dict)
    #         return _state_types(state, value, note_dict, cday = cday)
    #     except:
    #         _write_note(note_dict, value, state)
    # else:
    #     return _error(state)
    # return True
    trace = get_trace()
    if trace is not None:
        res = gtc.get_all_by_path(
            [x.strip() for x in trace['path'].split(',')])
        if trace['sha1'] not in res:
            remove_trace()
            trace = None

    # q = input('Would you like to end it before you start a new time? y/n: ').lower().strip()
    if state is 'start':
        if not trace:
            if _custom_check(value) is False:
                return False
            temp_note = _write_note(note_dict, value, state, cday=cday)
            trace = {}
            trace['sha1'] = shared.sha1_gen_dict(temp_note)
            username = shared.get_git_variables()['username']
            year = datetime.now().year
            month = datetime.now().month
            trace['path'] = username + ', ' + str(year) + ', ' + str(month)
            save_trace(trace)
        else:  # trace found
            logging.error('last one not ended')
            #TODO give context of the one open
            while (True):
                q = input(
                    'Would you like to end it before you start a new time? y/n: '
                ).lower().strip()
                if q == 'y' or q == 'yes':
                    #TODO end unfinished, remove trace, store start and save trace
                    time_end = None
                    try:
                        chour, cminute = _split_time_value(value)
                        if cday is not None:
                            time_end = metadata.time(chour=chour,
                                                     cminute=cminute,
                                                     cday=cday)
                        else:
                            time_end = metadata.time(chour=chour,
                                                     cminute=cminute)
                    except:
                        time_end = metadata.time()
                    gtc.store(
                        target=[x.strip() for x in trace['path'].split(',')],
                        append=trace['sha1'],
                        content={'timestamp_end': time_end})
                    remove_trace()
                    temp_note = _write_note(note_dict, value, state, cday=cday)
                    trace = {}
                    trace['sha1'] = shared.sha1_gen_dict(temp_note)
                    username = shared.get_git_variables()['username']
                    year = datetime.now().year
                    month = datetime.now().month
                    trace['path'] = username + ', ' + str(year) + ', ' + str(
                        month)
                    save_trace(trace)
                    break
                elif q == 'n' or q == 'no':
                    #TODO store start and overwrite trace
                    remove_trace()
                    temp_note = _write_note(note_dict, value, state, cday=cday)
                    trace = {}
                    trace['sha1'] = shared.sha1_gen_dict(temp_note)
                    username = shared.get_git_variables()['username']
                    year = datetime.now().year
                    month = datetime.now().month
                    trace['path'] = username + ', ' + str(year) + ', ' + str(
                        month)
                    save_trace(trace)
                    break
    else:
        trace = get_trace()
        time_end = None
        try:
            chour, cminute = _split_time_value(value)
            if cday is not None:
                time_end = metadata.time(chour=chour,
                                         cminute=cminute,
                                         cday=cday)
            else:
                time_end = metadata.time(chour=chour, cminute=cminute)
        except:
            time_end = metadata.time()
        gtc.store(target=[x.strip() for x in trace['path'].split(',')],
                  append=trace['sha1'],
                  content={'timestamp_end': time_end})
        remove_trace()