Skip to content

Commit

Permalink
Used color instead of extra field
Browse files Browse the repository at this point in the history
clsoe #520
  • Loading branch information
StephanAkkerman committed Apr 3, 2024
1 parent 11b31db commit 8c59180
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/util/sentiment_analyis.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
"BEARISH": "🐻",
}

color_table = {
"🦆": discord.Colour.lighter_grey(),
"🐂": discord.Colour.green(),
"🐻": discord.Colour.red(),
}


def preprocess_text(tweet: str) -> str:
# Replace URLs with URL token
Expand All @@ -41,7 +47,7 @@ def preprocess_text(tweet: str) -> str:
return tweet


def classify_sentiment(text: str) -> tuple[str, str]:
def classify_sentiment(text: str) -> str:
"""
Uses the text of a tweet to classify the sentiment of the tweet.
Expand All @@ -59,9 +65,7 @@ def classify_sentiment(text: str) -> tuple[str, str]:
label = pipe(preprocess_text(text))[0].get("label")
emoji = label_to_emoji[label]

label = f"{emoji} - {label.capitalize()}"

return label, emoji
return emoji


def add_sentiment(e: discord.Embed, text: str) -> tuple[discord.Embed, str]:
Expand All @@ -85,12 +89,9 @@ def add_sentiment(e: discord.Embed, text: str) -> tuple[discord.Embed, str]:
"""

# Remove quote tweet formatting
prediction, emoji = classify_sentiment(text.split("\n\n> [@")[0])
emoji = classify_sentiment(text.split("\n\n> [@")[0])

e.add_field(
name="Sentiment",
value=f"{prediction}",
inline=False,
)
# Change color based on sentiment
e.colour = color_table[emoji]

return e, emoji

0 comments on commit 8c59180

Please sign in to comment.