mirror of
https://github.com/AquaMorph/dotfiles.git
synced 2025-04-29 17:25:34 +00:00
Robot photo based on match schedules
This commit is contained in:
parent
a6d30fd86a
commit
4968769ba7
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
import configparser
|
import configparser
|
||||||
import datetime as dt
|
import datetime as dt
|
||||||
|
import re
|
||||||
import operator
|
import operator
|
||||||
import os
|
import os
|
||||||
import tbapy
|
import tbapy
|
||||||
@ -17,6 +18,22 @@ def getProjectID(api, name):
|
|||||||
print('Error: No project with the name {} found'.format(name))
|
print('Error: No project with the name {} found'.format(name))
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
# getChecklistName()
|
||||||
|
def getChecklistName(evemt):
|
||||||
|
return '{} Photos'.format(event['name'])
|
||||||
|
|
||||||
|
# getEventListID() returns the id of the checklist for the event and if there is none
|
||||||
|
# returns -1.
|
||||||
|
def getEventListID(items, event):
|
||||||
|
for item in items:
|
||||||
|
if item['content'] == getChecklistName(event):
|
||||||
|
return item['id']
|
||||||
|
return -1
|
||||||
|
|
||||||
|
# matchToTeamList() converts a match to two lists of teams
|
||||||
|
def matchToTeamList(match):
|
||||||
|
return match['alliances']['red']['team_keys'], match['alliances']['blue']['team_keys']
|
||||||
|
|
||||||
# createChecklistItem() creates a checklist item of the highest priority.
|
# createChecklistItem() creates a checklist item of the highest priority.
|
||||||
def createChecklistItem(name, api, projectID, item, date):
|
def createChecklistItem(name, api, projectID, item, date):
|
||||||
return api.items.add(name,
|
return api.items.add(name,
|
||||||
@ -88,7 +105,8 @@ todoistToken = configParser.get('Settings', 'TodoistToken')
|
|||||||
# Setup Todoist
|
# Setup Todoist
|
||||||
api = todoist.TodoistAPI(todoistToken)
|
api = todoist.TodoistAPI(todoistToken)
|
||||||
api.sync()
|
api.sync()
|
||||||
projectID = getProjectID(api, 'Test')
|
projectID = getProjectID(api, 'Test01')
|
||||||
|
items = api.state['items']
|
||||||
|
|
||||||
# Setup the Blue Alliance
|
# Setup the Blue Alliance
|
||||||
tba = tbapy.TBA(tbaKey)
|
tba = tbapy.TBA(tbaKey)
|
||||||
@ -99,26 +117,56 @@ day1 = (dt.datetime.strptime(setupDay, '%Y-%m-%d') + dt.timedelta(days=1)).strft
|
|||||||
day2 = event['end_date']
|
day2 = event['end_date']
|
||||||
teams = sorted(tba.event_teams(eventKey), key=operator.attrgetter('team_number'))
|
teams = sorted(tba.event_teams(eventKey), key=operator.attrgetter('team_number'))
|
||||||
|
|
||||||
# Create checklist
|
def firstMatch(team, matches):
|
||||||
checklist = api.items.add('{} Photos'.format(event['name']),
|
for match in matches:
|
||||||
project_id=projectID,
|
red, blue = matchToTeamList(match)
|
||||||
date_string=day2,
|
if team in red:
|
||||||
priority=2)
|
return match, 'red'
|
||||||
|
elif team in blue:
|
||||||
|
return match, 'blue'
|
||||||
|
return None, None
|
||||||
|
|
||||||
# Setup
|
# Check if list already exists
|
||||||
createPitList(api, teams, projectID, checklist, setupDay)
|
eventListID = getEventListID(items, event)
|
||||||
createChecklistItem('**Schedule** Judges photo', api, projectID, checklist, setupDay)
|
if eventListID == -1:
|
||||||
createChecklistItem('**Schedule** Inspectors photo', api, projectID, checklist, setupDay)
|
# Create checklist
|
||||||
createChecklistItem('**Schedule** Seniors photo', api, projectID, checklist, setupDay)
|
checklist = api.items.add(getChecklistName(event),
|
||||||
createGroupsList(api, projectID, checklist, setupDay)
|
project_id=projectID,
|
||||||
# Day 1
|
date_string=day2,
|
||||||
createPhotoChecklistItem('Guest Speakers', api, projectID, checklist, day1)
|
priority=2)
|
||||||
createRobotList(api, teams, projectID, checklist, day1)
|
# Setup
|
||||||
# Day 2
|
createPitList(api, teams, projectID, checklist, setupDay)
|
||||||
createPhotoChecklistItem('Guest Speakers', api, projectID, checklist, day2)
|
createChecklistItem('**Schedule** Judges photo', api, projectID, checklist, setupDay)
|
||||||
createPhotoChecklistItem('Mentors after parade', api, projectID, checklist, day2)
|
createChecklistItem('**Schedule** Inspectors photo', api, projectID, checklist, setupDay)
|
||||||
createPhotoChecklistItem('Seniors', api, projectID, checklist, day2)
|
createChecklistItem('**Schedule** Seniors photo', api, projectID, checklist, setupDay)
|
||||||
createPhotoChecklistItem('Alliances Representatives', api, projectID, checklist, day2)
|
createGroupsList(api, projectID, checklist, setupDay)
|
||||||
createWinnersList(api, projectID, checklist, day2)
|
# Day 1
|
||||||
createChecklistItem('**Email** guest speakers and winners photos', api, projectID, checklist, day2)
|
createPhotoChecklistItem('Guest Speakers', api, projectID, checklist, day1)
|
||||||
|
createRobotList(api, teams, projectID, checklist, day1)
|
||||||
|
# Day 2
|
||||||
|
createPhotoChecklistItem('Guest Speakers', api, projectID, checklist, day2)
|
||||||
|
createPhotoChecklistItem('Mentors after parade', api, projectID, checklist, day2)
|
||||||
|
createPhotoChecklistItem('Seniors', api, projectID, checklist, day2)
|
||||||
|
createPhotoChecklistItem('Alliances Representatives', api, projectID, checklist, day2)
|
||||||
|
createWinnersList(api, projectID, checklist, day2)
|
||||||
|
createChecklistItem('**Email** guest speakers and winners photos', api, projectID, checklist, day2)
|
||||||
|
else:
|
||||||
|
print('List already created')
|
||||||
|
matches = sorted(tba.event_matches(eventKey), key=operator.attrgetter('time'))
|
||||||
|
if not matches:
|
||||||
|
print('No match schedule yet')
|
||||||
|
else:
|
||||||
|
photoParentID = [item['id'] for item in items if 'parent_id' in item
|
||||||
|
and item['parent_id'] == eventListID
|
||||||
|
and 'Robot Photos' in item['content']][0]
|
||||||
|
robotPhotoList = [item for item in items if 'Robot photo of' in item['content']
|
||||||
|
and item['parent_id'] == photoParentID]
|
||||||
|
for robot in robotPhotoList:
|
||||||
|
if 'match' not in robot['content']:
|
||||||
|
team = 'frc{}'.format(re.findall(r'\d+', robot['content'])[0])
|
||||||
|
match, side = firstMatch(team, matches)
|
||||||
|
if match != None:
|
||||||
|
matchNumber = match['match_number']
|
||||||
|
matchTime = dt.datetime.fromtimestamp(match['time']).strftime('%Y-%m-%d %I:%M %p')
|
||||||
|
robot.update(date_string=matchTime, content='{} match {} {}'.format(robot['content'], matchNumber, side))
|
||||||
api.commit()
|
api.commit()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user