Skip to content
This repository has been archived by the owner on May 21, 2023. It is now read-only.

Commit

Permalink
Record extra info on tweetable_plays, for #33
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-finley committed Oct 12, 2022
1 parent b5df690 commit 3f8771a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
10 changes: 7 additions & 3 deletions clients/bigquery_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions clients/twitter_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions my_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3f8771a

Please sign in to comment.