From a94b14769ad7d578bdcc4b14462e29d833b79ac7 Mon Sep 17 00:00:00 2001 From: Christian Colglazier Date: Mon, 10 Feb 2020 16:21:08 -0500 Subject: [PATCH] Began framework for FRC photo checklist --- requirements.txt | 1 + scripts/frc-photo-checklist.py | 62 ++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 requirements.txt create mode 100644 scripts/frc-photo-checklist.py diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a25f34e --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +configparser todoist-python tbapy \ No newline at end of file diff --git a/scripts/frc-photo-checklist.py b/scripts/frc-photo-checklist.py new file mode 100644 index 0000000..fd1debd --- /dev/null +++ b/scripts/frc-photo-checklist.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 + +# Program to create a photo checklist of a given frc event. + +import configparser +import operator +import os +import tbapy +import todoist + +# getProjectID() returns the project id that matches the name given. +def getProjectID(api, name): + for project in api.state['projects']: + if project['name'] == name: + return project['id'] + print('Error: No project with the name {} found'.format(name)) + exit(1) + +# createPitList() creates a checklist for taking photos of a teams pit. +def createPitList(api, teams, projectID, checklist, date): + item = api.items.add('**Take** Pit Photos', + project_id=projectID, + parent_id=checklist['id'], + date_string=date, + priority=3) + for team in teams: + api.items.add('Pit photo of **{}** {}'.format(team['team_number'], team['nickname']), + project_id=projectID, + parent_id=item['id'], + date_string=date, + priority=4) + api.commit() + +# Parse settings config +configString = '[Settings]\n' + open('../settings.conf').read() +configParser = configparser.RawConfigParser() +configParser.read_string(configString) + +# Load needed credentials +tbaKey = configParser.get('Settings', 'TBAKey') +todoistToken = configParser.get('Settings', 'TodoistToken') + +# Setup Todoist +api = todoist.TodoistAPI(todoistToken) +api.sync() +projectID = getProjectID(api, 'Test') + +# Setup the Blue Alliance +tba = tbapy.TBA(tbaKey) +eventKey = '2020ncpem' +event = tba.event(eventKey) +teams = sorted(tba.event_teams(eventKey), key=operator.attrgetter('team_number')) + +checklist = api.items.add('{} Photos'.format(event['name']), + project_id=projectID, + date_string=event['end_date'], + priority=2) +api.commit() +createPitList(api, teams, projectID, checklist, event['start_date']) + +name = api.state['user']['full_name'] +print(name)