Пример #1
0
 def get_todays_health_bar(payload=None, socket=None):
     base = AirtableBase(HEALTH_BASE_ID)
     health_bar = base.retrieve_all_records_in_view('Health Bar', 'Today')
     socket.send_json({
         'type': 'GET_TODAYS_HEALTH_BAR_SUCCESS',
         'healthBar': health_bar[0]
     })
Пример #2
0
 def get_todays_water(payload=None, socket=None):
     base = AirtableBase(HEALTH_BASE_ID)
     water_log = base.retrieve_all_records_in_view('Water', 'Today')
     socket.send_json({
         'type': 'GET_TODAYS_WATER_SUCCESS',
         'waterLog': water_log[0] if len(water_log) else None
     })
Пример #3
0
 def get_yesterdays_meals(payload=None, socket=None):
     base = AirtableBase(HEALTH_BASE_ID)
     records = base.retrieve_all_records_in_view('Food Log', 'Yesterday')
     socket.send_json({
         'type': 'GET_YESTERDAYS_MEALS_SUCCESS',
         'meals': records
     })
Пример #4
0
 def get_point_rules(payload=None, socket=None):
     base = AirtableBase(MCL_BASE_ID)
     rules = base.retrieve_all_records('Point Rules')
     socket.send_json({
         'type': 'GET_POINT_RULES_SUCCESS',
         'pointRules': rules
     })
Пример #5
0
    def get_morning_checklist(payload=None, socket=None):
        base = AirtableBase(MCL_BASE_ID)
        records = base.retrieve_all_records_in_view('Checklists',
                                                    'Morning Checklist')

        record_map = {}
        for record in [r['fields'] for r in records]:
            category = record['Category Name'][0]
            if category in record_map:
                record_map[category].append({
                    'label': record['Name'],
                    'checked': False
                })
            else:
                record_map[category] = [{
                    'label': record['Name'],
                    'checked': False
                }]

        checklists = []
        for category in record_map:
            checklists.append({
                'name': category,
                'items': record_map[category]
            })

        socket.send_json({
            'type': 'GET_MORNING_CHECKLIST_SUCCESS',
            'checklists': checklists
        })
Пример #6
0
    def get_todays_active_minutes(payload=None, socket=None):
        base = AirtableBase(HEALTH_BASE_ID)
        log = base.retrieve_all_records_in_view('Activity Log', 'Today')

        socket.send_json({
            'type': 'GET_TODAYS_ACTIVE_MINUTES_SUCCESS',
            'activeMinutes': log
        })
Пример #7
0
 def get_todays_pomodoros(payload=None, socket=None):
     base = AirtableBase(MCL_BASE_ID)
     pomodoros = [
         r for r in base.retrieve_all_records_in_view('Pomodoros', 'Today')
     ]
     socket.send_json({
         'type': 'GET_TODAYS_POMODOROS_SUCCESS',
         'pomodoros': pomodoros
     })
Пример #8
0
 def set_current_pomodoro_time(payload=None, socket=None):
     base = AirtableBase(MCL_BASE_ID)
     if payload['active']:
         active = payload['active']
         active_pomodoro = base.update_record(
             'Pomodoros', active['id'], 'Time Left',
             active['Time Left'] - 1 if 'Time Left' in active else 1499)
         socket.send_json({
             'type': 'CURRENT_POMODORO_TIME_SENT',
             'active': active_pomodoro
         })
Пример #9
0
 def increment_active_pomodoro():
     base = AirtableBase(MCL_BASE_ID)
     pomodoros = DashboardApi.active_pomodoro()
     print(pomodoros)
     if len(pomodoros) > 0:
         record = base.update_record('Pomodoros', pomodoros[0]['id'],
                                     'Number',
                                     pomodoros[0]['fields']['Number'] + 1)
         print(record)
         return record
     return {}
Пример #10
0
    def get_current_pomodoro_time(payload=None, socket=None):
        base = AirtableBase(MCL_BASE_ID)
        active_pomodoros = [
            r
            for r in base.retrieve_all_records_in_view('Pomodoros', 'Active')
        ]

        socket.send_json({
            'type': 'CURRENT_POMODORO_TIME_SENT',
            'active': active_pomodoros[0]
        })
        return active_pomodoros[0]
Пример #11
0
    def log_water(payload=None, socket=None):
        base = AirtableBase(HEALTH_BASE_ID)
        water_log = base.retrieve_all_records_in_view('Water', 'Today')
        if len(water_log):
            todays_log = water_log[0]
            log = base.update_record('Water', todays_log['id'], 'Number',
                                     todays_log['fields']['Number'] + 1)
        else:
            log = base.create_record(
                'Water', {
                    'Number': 1,
                    'Date': datetime.now().strftime('%Y-%m-%d')
                })

        socket.send_json({'type': 'GET_TODAYS_WATER_SUCCESS', 'waterLog': log})
Пример #12
0
    def create_repeating_records(payload=None, socket=None):
        base = AirtableBase(MCL_BASE_ID)
        records = base.retrieve_all_records_in_view('Repeating', 'Active')

        for record in [r['fields'] for r in records]:
            fields = json.loads(record['fields'])
            new_record = {
                'Category': record['Category'],
                'Owner': record['Owner']
            }
            for field in fields:
                if field['method']:
                    new_record[field['name']] = getattr(
                        RepeatingMethods, field['value'])()
                else:
                    new_record[field['name']] = field['value']

            response = base.create_record(record['Table'], new_record)
            print(response)
        socket.send_json({'type': 'CREATE_REPEATING_RECORDS_SUCCESS'})
Пример #13
0
 def start_pomodoro_timer(payload=None, socket=None):
     base = AirtableBase(MCL_BASE_ID)
     active_pomodoros = [
         r
         for r in base.retrieve_all_records_in_view('Pomodoros', 'Active')
     ]
     if len(active_pomodoros) > 0:
         active_pomodoro = base.update_record('Pomodoros',
                                              active_pomodoros[0]['id'],
                                              'Started', True)
         socket.send_json({
             'type': 'POMODORO_TIMER_STARTED',
             'active': active_pomodoro
         })
     else:
         socket.send_json({
             'type': 'POMODORO_TIMER_STARTED',
             'active': {
                 'id': None
             }
         })
Пример #14
0
 def pomodoros_this_year():
     base = AirtableBase(MCL_BASE_ID)
     return base.retrieve_all_records_in_view('Pomodoros', 'This Year')
Пример #15
0
 def get_todays_tasks(payload=None, socket=None):
     base = AirtableBase(MCL_BASE_ID)
     tasks = [
         r for r in base.retrieve_all_records_in_view('Tasks', 'Today')
     ]
     socket.send_json({'type': 'GET_TODAYS_TASKS_SUCCESS', 'tasks': tasks})
Пример #16
0
 def log_compulsion(payload=None, socket=None):
     base = AirtableBase(HEALTH_BASE_ID)
     base.create_record('Compulsions', {})
Пример #17
0
 def weight_data():
     base = AirtableBase(HEALTH_BASE_ID)
     return [r for r in base.retrieve_all_records('Weight Log')]
Пример #18
0
 def me_inc_notes():
     base = AirtableBase(MCL_BASE_ID)
     return [
         r for r in base.retrieve_all_records_in_view('Notes', 'Me, Inc.')
     ]
Пример #19
0
 def yesterdays_pomodoros():
     base = AirtableBase(MCL_BASE_ID)
     return [
         r for r in base.retrieve_all_records_in_view(
             'Pomodoros', 'Yesterday')
     ]
Пример #20
0
 def active_pomodoro():
     base = AirtableBase(MCL_BASE_ID)
     return [
         r
         for r in base.retrieve_all_records_in_view('Pomodoros', 'Active')
     ]
Пример #21
0
 def __init__(self, git, airtable, is_test=False):
     self._git = git if git else GitRepo(TEST_REPO_NAME)
     self._airtable = airtable if airtable else AirtableBase(
         MCL_DEV_BASE_ID)
     self._log = []
     self._is_test = is_test