diff --git a/clients/bigquery_client.py b/clients/bigquery_client.py index eef4789..0cc8cd0 100644 --- a/clients/bigquery_client.py +++ b/clients/bigquery_client.py @@ -83,12 +83,16 @@ def add_tweetable_plays(self, tweetable_plays: list[TweetablePlay]) -> None: if deduped_play not in deduped_tweetable_plays: deduped_tweetable_plays.append(deduped_play) + # We could probably nix deduped_tweetable_plays, but for now assert that it's the same length + assert len(deduped_tweetable_plays) == len(tweetable_plays) + q = """ - INSERT INTO mlb_alphabet_game.tweetable_plays (game_id, play_id, sport, completed_at) + INSERT INTO mlb_alphabet_game.tweetable_plays (game_id, play_id, sport, completed_at, tweet_id, player_name, season_phrase) VALUES """ - for p in deduped_tweetable_plays: - q += f"('{p.game_id}', '{p.play_id}', '{self.league_code}', CURRENT_TIMESTAMP())," + for p in tweetable_plays: + assert p.tweet_id is not None + q += f"('{p.game_id}', '{p.play_id}', '{self.league_code}', CURRENT_TIMESTAMP(), {p.tweet_id}, '{p.player_name}', '{p.season_phrase}')," q = q[:-1] # remove trailing comma print(q) self.client.query(q, job_config=self.job_config).result() diff --git a/clients/twitter_client.py b/clients/twitter_client.py index 6eff58b..331198f 100644 --- a/clients/twitter_client.py +++ b/clients/twitter_client.py @@ -70,9 +70,11 @@ def tweet_matched( media_ids=[media.media_id], ) state.tweet_id = tweet.id + tweetable_play.tweet_id = tweet.id else: # Increment the tweet_id to test the BQ logic state.tweet_id += 1 + tweetable_play.tweet_id = state.tweet_id def tweet_unmatched(self, tweetable_play: TweetablePlay, state: State) -> None: if state.tweet_id: @@ -86,9 +88,11 @@ def tweet_unmatched(self, tweetable_play: TweetablePlay, state: State) -> None: in_reply_to_status_id=state.tweet_id, ) state.tweet_id = tweet.id + tweetable_play.tweet_id = tweet.id else: # Increment the tweet_id to test the BQ logic state.tweet_id += 1 + tweetable_play.tweet_id = state.tweet_id def _alert(self, matching_letters: list[str]) -> str: if len(matching_letters) == 1: diff --git a/my_types.py b/my_types.py index d6906e4..2441a17 100644 --- a/my_types.py +++ b/my_types.py @@ -162,6 +162,7 @@ class TweetablePlay: score: str # CIN (2) @ MIL (1) 🔺8 season_period: SeasonPeriod season_phrase: str # "in the 2022-23 season". Can be simplified once we don't need to support partial MLB season anymore. + tweet_id: int | None = None @dataclass