Integrate with Reddit.
This commit is contained in:
40
ticker_extractor.py
Normal file
40
ticker_extractor.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# ticker_extractor.py
|
||||
|
||||
import re
|
||||
|
||||
# A set of common English words and acronyms that look like stock tickers.
|
||||
# This helps reduce false positives.
|
||||
COMMON_WORDS_BLACKLIST = {
|
||||
"A", "I", "DD", "CEO", "CFO", "CTO", "EPS", "IPO", "YOLO", "FOMO",
|
||||
"TLDR", "EDIT", "THE", "AND", "FOR", "ARE", "BUT", "NOT", "YOU",
|
||||
"ALL", "ANY", "CAN", "HAS", "NEW", "NOW", "OLD", "SEE", "TWO",
|
||||
"WAY", "WHO", "WHY", "BIG", "BUY", "SELL", "HOLD", "BE", "GO",
|
||||
"ON", "AT", "IN", "IS", "IT", "OF", "OR", "TO", "WE", "UP",
|
||||
"OUT", "SO", "RH", "SEC", "IRS", "USA", "UK", "EU",
|
||||
"AI", "ML", "AR", "VR", "NFT", "DAO", "WEB3", "ETH", "BTC",
|
||||
"USD", "EUR", "GBP", "JPY", "CNY", "INR", "AUD", "CAD", "CHF",
|
||||
"RUB", "ZAR", "BRL", "MXN", "HKD", "SGD", "NZD", "RSD",
|
||||
"JPY", "KRW", "SEK", "NOK", "DKK", "PLN", "CZK", "HUF", "TRY",
|
||||
"US", "IRA", "FDA", "SEC", "FBI", "CIA", "NSA", "NATO",
|
||||
}
|
||||
|
||||
def extract_tickers(text):
|
||||
"""
|
||||
Extracts potential stock tickers from a given piece of text.
|
||||
A ticker is identified as a 1-5 character uppercase word, or a word prefixed with $.
|
||||
"""
|
||||
# Regex to find potential tickers:
|
||||
# 1. Words prefixed with $: $AAPL, $TSLA
|
||||
# 2. All-caps words between 1 and 5 characters: GME, AMC
|
||||
ticker_regex = r"\$[A-Z]{1,5}\b|\b[A-Z]{1,5}\b"
|
||||
|
||||
potential_tickers = re.findall(ticker_regex, text)
|
||||
|
||||
# Filter out common words and remove the '$' prefix
|
||||
tickers = []
|
||||
for ticker in potential_tickers:
|
||||
cleaned_ticker = ticker.replace("$", "").upper()
|
||||
if cleaned_ticker not in COMMON_WORDS_BLACKLIST:
|
||||
tickers.append(cleaned_ticker)
|
||||
|
||||
return tickers
|
Reference in New Issue
Block a user