From 2bf63cfed928d810dc8729bf78a76134e3892496 Mon Sep 17 00:00:00 2001 From: Flip-Liquid <13227294+Flip-Liquid@users.noreply.github.com> Date: Wed, 21 Jun 2023 19:57:14 -0400 Subject: [PATCH] auto-create guild contribution associated with guild for integration (#581) --- .../twitter_contribution/graphql.py | 11 ++++++++++- .../twitter_contribution/process.py | 6 +++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/apps/jobs/twitter-contribution/twitter_contribution/graphql.py b/apps/jobs/twitter-contribution/twitter_contribution/graphql.py index 6b3ca80e3..f7f52036b 100644 --- a/apps/jobs/twitter-contribution/twitter_contribution/graphql.py +++ b/apps/jobs/twitter-contribution/twitter_contribution/graphql.py @@ -282,7 +282,7 @@ async def create_job_run(name: str, start: str, end: str): async def create_twitter_hashtag_contribution( - tweet: Tweet, user_id: int, user_name: str, hashtag: str + tweet: Tweet, user_id: int, user_name: str, hashtag: str, guild_id: int ): mutation = """ mutation createStagedContribution($data: ContributionCreateInput!) { @@ -327,6 +327,15 @@ async def create_twitter_hashtag_contribution( } } }, + "guilds": { + "create": { + "guild": { + "connect": { + "id": guild_id, + } + } + } + }, } }, ) diff --git a/apps/jobs/twitter-contribution/twitter_contribution/process.py b/apps/jobs/twitter-contribution/twitter_contribution/process.py index 729e8a6be..381d2abe7 100644 --- a/apps/jobs/twitter-contribution/twitter_contribution/process.py +++ b/apps/jobs/twitter-contribution/twitter_contribution/process.py @@ -36,7 +36,7 @@ async def process_guild_integrations(): logger.info(f"Processing tweets for hashtag {hashtag} since {since}") tweets = await retrieve_tweets(hashtag, since) logger.info(f"Retrieved {len(tweets)} tweets for hashtag {hashtag}") - await process_tweets(integration, tweets) + await process_tweets(integration, tweets, guild["id"]) # TODO: err handling logger.info(f"Processed {len(tweets)} tweets for hashtag {hashtag}") @@ -46,7 +46,7 @@ async def process_guild_integrations(): # TODO: parallelize -async def process_tweets(guild_integration, tweets: list[Tweet]): +async def process_tweets(guild_integration, tweets: list[Tweet], guild_id: int): for tweet in tweets: # check if user has profile and linked twitter account user = await get_user_by_twitter(tweet.profile_handle) @@ -82,5 +82,5 @@ async def process_tweets(guild_integration, tweets: list[Tweet]): f"Creating contribution for tweet {tweet.id} by user {tweet.profile_handle}" ) await create_twitter_hashtag_contribution( - tweet, user["id"], user["name"], guild_integration["hashtag"] + tweet, user["id"], user["name"], guild_integration["hashtag"], guild_id )