This Django-based web service analyzes Twitter data to provide user recommendations based on tweet interactions, hashtags, and keywords. It uses PostgreSQL for data storage and is optimized for performance with caching.
-
ETL Process (
api/etl.py
)- Extracts, transforms, and loads Twitter data from a JSON file into PostgreSQL.
-
Data Models (
api/models.py
)- Tweet Model: Stores tweet details.
- User Model: Stores user information.
-
API Endpoint (
api/views.py
)/api/q2
: Provides user recommendations based on interaction, hashtag, and keyword scores.
-
URL Configuration (
api/urls.py
)- Maps API endpoint to the view.
-
Settings (
twitter_analysis/settings.py
)- Configures Django settings and PostgreSQL database.
-
Testing (
api/tests.py
)- Unit tests for the API endpoint.
- Python 3.8+
- Django 4.2.5
- PostgreSQL
-
Clone the repo:
git clone https://github.com/yourusername/twitter_analysis.git cd twitter_analysis
-
Set up virtual environment and install dependencies:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate` pip install -r requirements.txt
-
Configure PostgreSQL in
twitter_analysis/settings.py
. -
Run migrations:
python manage.py migrate
Run the ETL process to load data:
python manage.py load_tweets path/to/tweets.json
Start the development server:
python manage.py runserver
Run tests to check functionality:
python manage.py test
-
Endpoint:
/api/q2
-
Method: GET
-
Parameters:
user_id
(required): User ID for recommendations.type
(required): Interaction type (reply
,retweet
,both
).phrase
(required): Keyword phrase.hashtag
(required): Hashtag.
-
Response:
{ "recommendations": [ { "user_id": "12345", "screen_name": "user123", "description": "User description", "contact_tweet_text": "Latest tweet text" } ] }