def get_event_info_str(event_name, season=None): my_config = ScoutingAppMainWebServer.global_config if event_name.startswith("201"): year = event_name[0:4] event_code = event_name[4:] else: if season == None: year = my_config["this_season"] else: year = season event_code = event_name event_dict = WebEventData.get_event_info_dict(my_config, year, event_code) event_info_str = list() if event_dict: event_info_str.append(("Name", event_dict["name"], "string")) event_info_str.append(("Code", event_dict["event_code"].upper(), "string")) event_info_str.append(("Location", event_dict["location"], "string")) event_info_str.append(("Start Date", event_dict["start_date"], "string")) event_info_str.append(("End Date", event_dict["end_date"], "string")) else: event_info_str.append(("Name", "Unknown", "string")) event_info_str.append(("Code", "NONE", "string")) return event_info_str
def get_event_info_str(event_name, season=None): my_config = ScoutingAppMainWebServer.global_config if event_name.startswith('201'): year = event_name[0:4] event_code = event_name[4:] else: if season == None: year = my_config['this_season'] else: year = season event_code = event_name event_dict = WebEventData.get_event_info_dict(my_config, year, event_code) event_info_str=list() if event_dict: event_info_str.append(('Name',event_dict['name'],'string')) event_info_str.append(('Code',event_dict['event_code'].upper(),'string')) event_info_str.append(('Location',event_dict['location'],'string')) event_info_str.append(('Start Date',event_dict['start_date'],'string')) event_info_str.append(('End Date',event_dict['end_date'],'string')) else: event_info_str = None return event_info_str
def GET(self): WebLogin.check_access(global_config,10) request_data = web.input() try: season = request_data.Year except: season = global_config['this_season'] try: event_type = request_data.Type event_type = 'NE' except: event_type = None if event_type != None: result = WebEventData.get_district_events_json(global_config, season, event_type) else: result = WebEventData.get_events_json(global_config, season, event_type) return result
def GET(self, param_str): WebLogin.check_access(global_config,10) result = '' params = param_str.split('/') if len(params) == 2: year = params[0][0:4] event_code = params[0][4:] table = params[1] if table == 'qual': table_to_parse = 2 elif table == 'elim': table_to_parse = 3 else: table_to_parse = 2 result = WebEventData.get_event_matchresults_json(global_config, year, event_code, table_to_parse) return result
def GET(self, name): WebLogin.check_access(global_config,10) year = name[0:4] event_code = name[4:] result = WebEventData.get_event_results_page(global_config, year, event_code) return render.page('FIRST Robotics Event Match Results - %s' % event_code.upper(), result)
def GET(self, name): WebLogin.check_access(global_config,10) year = name[0:4] event_code = name[4:] result = WebEventData.get_event_standings_json(global_config, year, event_code) return result
def processClientConnection( self, client_sock, client_info ): print "Accepted connection from ", client_info files_received = 0 try: while True: msg_header, msg_body, content_type = self.read_request( client_sock ) if len(msg_header) == 0: break print "Message Header: %s" % msg_header print "Message Body Length: %d" % len(msg_body) msg_header_lines = msg_header.splitlines() request_type, request_path = msg_header_lines[0].split(' ',1) print "Request Type: %s" % request_type print "Request Path: %s" % request_path request_complete = False # retrieve any params attached to the requested entity params_offset = request_path.find('?') if params_offset != -1: request_params = request_path[params_offset:] request_params = request_params.lstrip('?') request_path = request_path[0:params_offset] request_path = request_path.lstrip('/') # if the requested path starts with 'static', then let's assume that # the request knows the full path that it's looking for, otherwise, # we will prepend the path with the path to the data directory if request_path.startswith('static'): fullpath = './' + request_path else: fullpath = './static/data/' + request_path if request_type == "PUT": # make sure that the destination directory exists if not os.path.exists(os.path.dirname(fullpath)): os.makedirs(os.path.dirname(fullpath)) response_code = FileSync.put_file(fullpath, content_type, msg_body) client_sock.send('HTTP/1.1 ' + response_code + '\r\n') files_received += 1 elif request_type == "POST": response_code = "400 Bad Request" path_elems = request_path.split('/') if len(path_elems) >= 2: comp_season_list = WebCommonUtils.split_comp_str(path_elems[0]) if comp_season_list != None: result = False error = False # for the sync of event and team data, the URI path is of the following # format /Sync/<comp>/EventData/[TeamData/]. if just EventData is provided, # then the event data is regenerated, if TeamData is provided, then both # the event data and team data is regenerated if len(path_elems) >= 2 and path_elems[1] == 'EventData': result = WebEventData.update_event_data_files( self.global_config, comp_season_list[1], comp_season_list[0], path_elems[1] ) if result == True: result = WebTeamData.update_team_event_files( self.global_config, comp_season_list[1], comp_season_list[0], path_elems[1] ) if result == True: result = WebAttributeDefinitions.update_event_data_files( self.global_config, path_elems[1] ) if result == False: error = True if len(path_elems) >= 3 and path_elems[2] == 'TeamData' and error is False: try: team = path_elems[3] if team == '': team = None except: team = None result = WebTeamData.update_team_data_files( self.global_config, comp_season_list[1], comp_season_list[0], path_elems[2], team ) if result == True: response_code = "200 OK" client_sock.send('HTTP/1.1 ' + response_code + '\r\n') elif request_type == "GET": # Parse any params attached to this GET request params = request_params.split(';') for param in params: # split the parameter into the tag and value parsed_param = param.split('=') tag = parsed_param[0] value = parsed_param[1] # process the parameter # check to see if the requested path exists. We may need to handle that # condition separately, treating non-existent directories as empty (as # opposed to sending a 404 not found. # TODO: update the client side to handle the 404 not found as an empty directory # and then update this block to send the 404 in all cases. if not os.path.exists(fullpath): if request_path[-1] == '/': # if the requested path refers to a directory, let's return an empty # response indicating that there are no files in that directory client_sock.send('HTTP/1.1 ' + '200 OK' + '\r\n') client_sock.send('Content-Length: 0\r\n') client_sock.send('\r\n\r\n') else: client_sock.send('HTTP/1.1 ' + '404 Not Found' + '\r\n\r\n') request_complete = True if not request_complete: if os.path.isdir(fullpath): file_list = FileSync.get_file_list(fullpath) response_body = '' for file_name in file_list: response_body += file_name + '\n' client_sock.send('HTTP/1.1 ' + '200 OK' + '\r\n') client_sock.send('Content-Length: %d\r\n' % len(response_body)) client_sock.send('\r\n') client_sock.send(response_body + '\r\n') else: response_body = FileSync.get_file(fullpath) if response_body != '': client_sock.send('HTTP/1.1 ' + '200 OK' + '\r\n') client_sock.send('Content-Length: %d\r\n' % len(response_body)) client_sock.send('\r\n') client_sock.send(response_body + '\r\n') else: client_sock.send('HTTP/1.1 ' + '404 Not Found' + '\r\n\r\n') print "Request Complete\n" except IOError: pass print "disconnected" client_sock.close()