game_meta = {}\r
events = {}\r
players = []\r
+ teams = []\r
+\r
+ # we're not in either stanza to start\r
+ in_P = in_Q = False\r
\r
for line in body.split('\n'):\r
try:\r
if key in 'S' 'n':\r
value = unicode(value, 'utf-8')\r
\r
- if key not in 'P' 'n' 'e' 't' 'i':\r
+ if key not in 'P' 'Q' 'n' 'e' 't' 'i':\r
game_meta[key] = value\r
\r
- if key == 'P':\r
- # if we were working on a player record already, append\r
- # it and work on a new one (only set team info)\r
- if len(events) > 0:\r
+ if key == 'Q' or key == 'P':\r
+ #log.debug('Found a {0}'.format(key))\r
+ #log.debug('in_Q: {0}'.format(in_Q))\r
+ #log.debug('in_P: {0}'.format(in_P))\r
+ #log.debug('events: {0}'.format(events))\r
+\r
+ # check where we were before and append events accordingly\r
+ if in_Q and len(events) > 0:\r
+ #log.debug('creating a team (Q) entry')\r
+ teams.append(events)\r
+ events = {}\r
+ elif in_P and len(events) > 0:\r
+ #log.debug('creating a player (P) entry')\r
players.append(events)\r
events = {}\r
\r
+ if key == 'P':\r
+ #log.debug('key == P')\r
+ in_P = True\r
+ in_Q = False\r
+ elif key == 'Q':\r
+ #log.debug('key == Q')\r
+ in_P = False\r
+ in_Q = True\r
+\r
events[key] = value\r
\r
if key == 'e':\r
# no key/value pair - move on to the next line\r
pass\r
\r
- # add the last player we were working on\r
- if len(events) > 0:\r
+ # add the last entity we were working on\r
+ if in_P and len(events) > 0:\r
players.append(events)\r
+ elif in_Q and len(events) > 0:\r
+ teams.append(events)\r
\r
- return (game_meta, players)\r
+ return (game_meta, players, teams)\r
\r
\r
def is_blank_game(gametype, players):\r
"----- END REQUEST BODY -----\n\n")\r
\r
(idfp, status) = verify_request(request)\r
- (game_meta, raw_players) = parse_stats_submission(request.body)\r
+ (game_meta, raw_players, raw_teams) = parse_stats_submission(request.body)\r
revision = game_meta.get('R', 'unknown')\r
duration = game_meta.get('D', None)\r
\r