TBA-API to end all TBA-APIs. (Java)

With the new robotics season already started up, I figured a powerful TBA API would be useful to some of you. I built a scouting app a while back and was noticing that all the Java APIs that I found on the TBA api-docs page didn’t work very well and were always breaking.

So I created my own API. Everything (all methods) has (have) been tested thoroughly on both the PC and Android. It contains a method for EVERY single pull request listed on the TBA api page. It’s also got tons of configuration settings for how to pull data, along with a testing class, a full-fledged github wiki with installation, tutorials, and working examples. Let me know if you find this project useful! Knowing that people are using and enjoy my API drives me to make it better!

Here’s the link:
https://github.com/techguy9984/TBA-API

3 Likes

This would be really cool if I used Java. I’m not very good at it myself, so I’ve been using requests in Python for my TBA pulls, it makes things pretty user friendly. If I ever make the switch I’ll be sure to keep this in mind. Thanks for posting.

1 Like

Are you using a certain library or just urllib requests? I tried using the Python library recommended on the API docs by TBA but kept on getting a 403 error. Apparently they’re blocking calls without a User-Agent.

Yeah that didn’t used to be the case, but then we put everything behind Cloudflare, which apparently requires a user agent to be set. Must have broken that library.

Yes I am using the requests library, I couldn’t get urllib to work either. You can get requests from here.

I recommend the pip install since it’s really easy. If you don’t have pip the walk through is pretty good.

PM me and I can send you some sample code, I don’t want to derail this thread too much.

If Maven isn’t too much hassle to you, I’d appreciate it. It makes updating super easy, and is how I normally build projects.

So I was looking at the API guide thats in google for TBA and I didn’t seem to find an API for pulling the match schedule for an event. Is there an API for this?

Yes in fact there is. The Blue Alliance API Google Sheets Addon. This script has a ton of APIs for google sheets including match schedule. It’s a little confusing to understand it, but if you can it does a lot and is really easy to use.

I’m glad you enjoy it! Is there anything I can do that would make it a little easier to understand?

I love it. It’s just that it did take me an hour or so to install the API. I tink the directions could be fleshed out a little more so that oher people canhave an easier time using it. I dodn’t have that much of an idea of how you did it, but I would be happy to help!

Not sure how I’ve never seen this thread before, but this has existed for a few years now (originally made by me, then tweaked and expanded by @tweirtx). Supports a number of languages (happy to add more if there’s a need).

@ Hailey.faiella We ran into that question last summer when were were trying to develop our own Scouting App. We wanted a digital copy of the Tournament Match Schedule, and also one for just our matches.
We ultimately wrote a python script that generates two Excel worksheets. One for the Tournament, one for just our team.

Once generated, these two worksheets get integrated and utilized in our Scouting App.
The is written to run on a RPi. As it is here, it will scrape the 2020 event schedule for ‘week0’, and will also create a schedule for team 2073 at that tournament. Additionally, it will display the local time for these matches.
To modify this for your use:

  1. Add your own TBA Key
  2. Set the year desired (not needed for 2020)
  3. Set the event code for the tournament desired. (Available through a different API call)
  4. Set your team number
  5. Set the UBT offset for your location.

import os
import tbapy
from openpyxl import Workbook
from openpyxl.styles import PatternFill #, Font, Border
from openpyxl.formatting.rule import CellIsRule #, FormulaRule, ColorScaleRule
import datetime

#------------------Set year, event code, Team number, and Time Zone offset here.------------------
Year = 2020 #Enter the year foe which you want the schedule
event = ‘week0’ #‘cafr’ #‘idbo’ #Enter the event code for the tournament you want the Match Schedule
TEAM = 2073 #Enter your team number here to get a sheet with just your team’s match schedule

UBToffset = -7 #Enter UBT Time zone offset for your location
#--------------------------------------------------------------------------------------------------------------

Event = str(Year)+event
#---------------------------------Clean up old files-----------------
#This will provide clean date without corruption from earlier runs
if os.path.exists(’/EagleScout/Python Scripts/Match_Schedule/Match_Schdule.xlsx’):
os.remove (’/EagleScout/Python Scripts/Match_Schedule/Match_Schdule.xlsx’)

if os.path.exists(’/EagleScout/Python Scripts/Match_Schedule/Match_Schdule.csv’):
os.remove (’/EagleScout/Python Scripts/Match_Schedule/Match_Schdule.csv’)
#---------------------------------End of Clean up---------------------

#--------------------------------Fill pattern for conditional formatting--------------------
greenFill = PatternFill(start_color=‘ACF99D’, end_color=‘ACF99D’, fill_type=‘solid’)

#My personal TBA Key
tba = tbapy.TBA(‘Put Your Own TBA Key Here’)

#----------Create workbook with two worksheets. One for the tournament, one for your Team---------
Tnmt = Workbook()
ws = Tnmt.active
ws.title = “Match Schedule”
ws2 = Tnmt.create_sheet( str(TEAM)+" Schedule")

def Alpha_scrape(value):
if (value.find(‘B’) != -1):
value = (value[:len(value)-1]) #Slice off the Alpha
if (len(value) == 3): # 3 digit team
value = (‘9’+value)
elif (len(value) == 2): # 2 digit team
value = (‘90’ + value)
elif (len(value) == 1): # 1 digit team
value = (‘900’ + value)
else: # 4 digit team
value = (‘9’+value[1:])
#print(str(value))
return value
elif (value.find(‘C’) != -1):
value = (value[:len(value)-1]) #Slice off the Alpha
if (len(value) == 3): # 3 digit team
value = (‘8’+value)
elif (len(value) == 2): # 2 digit team
value = (‘80’ + value)
elif (len(value) == 1): # 1 digit team
value = (‘800’ + value)
else:
value = (‘8’+value[1:])
#print(str(value))
return value

else:
    return value
    #print ("It not B Here")

#Query TBA for match schedule
schedule_keys = tba.event_matches(Event, simple=True, keys=True)
#print(schedule_keys)
Q = 0
for i in range (1, len(schedule_keys)):
result = tba.match(schedule_keys[i], simple=True)
if result.comp_level == ‘qm’:
Q += 1
#print(Q)
S = 1
for i in range (1, Q+1):
results = tba.match(Event + ‘_qm’ + str(i), simple=True)
if results.comp_level == ‘qm’ :
mn = results.match_number
tu = results.predicted_time
tm = datetime.datetime.utcfromtimestamp(tu +(UBToffset*(3600))) #Convert UNIX time to local time
R1 = results.alliances[‘red’][‘team_keys’][0]
R1 = R1[3:]
R1 = Alpha_scrape(R1)
R2 = results.alliances[‘red’][‘team_keys’][1]
R2 = R2[3:]
R2 = Alpha_scrape(R2)
R3 = results.alliances[‘red’][‘team_keys’][2]
R3 = R3[3:]
R3 = Alpha_scrape(R3)
B1 = results.alliances[‘blue’][‘team_keys’][0]
B1 = B1[3:]
B1 = Alpha_scrape(B1)
B2 = results.alliances[‘blue’][‘team_keys’][1]
B2 = B2[3:]
B2 = Alpha_scrape(B2)
B3 = results.alliances[‘blue’][‘team_keys’][2]
B3 = B3[3:]
B3 = Alpha_scrape(B3)
ws.cell(row = 1+S, column = 1).value = mn
ws.cell(row = 1+S, column = 2).value = tm
ws.cell(row = 1+S, column = 3).value = R1
ws.cell(row = 1+S, column = 4).value = R2
ws.cell(row = 1+S, column = 5).value = R3
ws.cell(row = 1+S, column = 6).value = B1
ws.cell(row = 1+S, column = 7).value = B2
ws.cell(row = 1+S, column = 8).value = B3
ws.cell(row = 1+S, column = 2).number_format = ‘HH:MM’ #Restrict to display time only
S += 1
H = 0
Headers = [‘Match #’, ‘Time’, ‘Red 1’, ‘Red 2’, ‘Red 3’, ‘Blue 1’, ‘Blue 2’, ‘Blue 3’]
for h in Headers:
ws.cell(row =1, column = 1 + H).value = Headers[H]
ws2.cell(row =1, column = 1 + H).value = Headers[H]
H += 1

S = 1
Tm_Sched = tba.team_matches(TEAM, Event, simple = True, keys = True)
#print(Tm_Sched)

for i in range (1, Q+1):
if Event + ‘_qm’ + str(i) in Tm_Sched:
#print(Event + ‘_qm’ + str(i))
results = tba.match(Event + ‘_qm’ + str(i), simple=True)
mn = results.match_number
tu = results.predicted_time
tm = datetime.datetime.utcfromtimestamp(tu +(UBToffset*(3600))) #Convert UNIX time to local time
R1 = results.alliances[‘red’][‘team_keys’][0]
R1 = R1[3:]
R1 = Alpha_scrape(R1)
R2 = results.alliances[‘red’][‘team_keys’][1]
R2 = R2[3:]
R2 = Alpha_scrape(R2)
R3 = results.alliances[‘red’][‘team_keys’][2]
R3 = R3[3:]
R3 = Alpha_scrape(R3)
B1 = results.alliances[‘blue’][‘team_keys’][0]
B1 = B1[3:]
B1 = Alpha_scrape(B1)
B2 = results.alliances[‘blue’][‘team_keys’][1]
B2 = B2[3:]
B2 = Alpha_scrape(B2)
B3 = results.alliances[‘blue’][‘team_keys’][2]
B3 = B3[3:]
B3 = Alpha_scrape(B3)

    ws2.cell(row = 1+S, column = 1).value = mn
    ws2.cell(row = 1+S, column = 2).value = tm
    ws2.cell(row = 1+S, column = 3).value = R1
    ws2.cell(row = 1+S, column = 4).value = R2
    ws2.cell(row = 1+S, column = 5).value = R3
    ws2.cell(row = 1+S, column = 6).value = B1
    ws2.cell(row = 1+S, column = 7).value = B2
    ws2.cell(row = 1+S, column = 8).value = B3
    ws2.cell(row = 1+S, column = 2).number_format = 'HH:MM' #Restrict to display time only
    S += 1

SN = Tnmt.get_sheet_by_name( ‘2073 Schedule’)
SN.conditional_formatting.add(‘C2:H14’, CellIsRule(operator=‘equal’, formula= [2073] , stopIfTrue=True, fill=greenFill))

SM = Tnmt.get_sheet_by_name( ‘Match Schedule’)
SM.conditional_formatting.add(‘C2:H130’, CellIsRule(operator=‘equal’, formula= [2073] , stopIfTrue=True, fill=greenFill))

Tnmt.save(’/EagleScout/Python Scripts/Match_Schedule/Match_Schdule.xlsx’)