An API that provides sentiment analysis for various purposes. It helps users understand the sentiment around topics such as stocks and cryptocurrencies using data from social media. Currently, the data comes exclusively from Reddit.
-
Clone the repository:
git clone https://github.com/your-username/sentiment-api.git cd sentiment-api -
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables:
- Create a
.envfile in the root directory and add your Reddit API credentials:
REDDIT_CLIENT_ID=your_client_id REDDIT_SECRET=your_secret REDDIT_USER_AGENT=your_user_agent
- Create a
-
Run the server locally:
python manage.py runserver
- Keyword-based Sentiment Analysis: Analyze sentiment based on specific keywords.
- Media Link Analysis: Perform sentiment analysis on articles and media content based on URLs.
Request sentiment analysis for a particular keyword (e.g., BTC):
GET /api/v1/sentiment/query?keyword=btc&limit=50&timeframe=weekResponse
{
"keyword": "nvda",
"sentiment_score": 0.85,
"limit": 50,
"timeframe": "week"
}- keyword (required): The keyword to analyze (e.g.,
btc,aapl). - limit (optional): The number of posts to analyze. Default is 10, and the maximum is 100.
- timeframe (optional): The time range to consider for the analysis. Default is
day. Available options are:hour: Last hourday: Last day (default)week: Last weekmonth: Last monthyear: Last year
Request sentiment analysis for a specific media link:
GET /api/v1/sentiment/links?link=https://example.com/articleResponse:
{
"link": "https://example.com/article",
"sentiment_score": 0.75
}- link (required): The link to analyze (e.g.,
https://example.com/article).
- This feature works best with static content such as news articles or blog posts.
- Dynamic content like social media posts or pages with JavaScript-rendered content may not be parsed correctly.
- Currently, only English language content is supported.
- The API rate limit is set to 100 requests per hour per IP.
- Each request can analyze a maximum of 512 characters per input. Texts longer than this limit will be truncated before analysis.