/news-api

Primary LanguagePython

News Parser API

Screencast:
Google drive link

1) Create and fill .env file, ensure you have latest docker-compose and Docker installed

.env file example:

MYSQL_DATABASE=mysql
MYSQL_USER=mysql
MYSQL_PASSWORD=pa$$word
MYSQL_ROOT_PASSWORD=pa$$word
HOST=mysql

DEBUG=False

2) In the root directory execute command:

docker-compose up -d

3) Execute command to parse and create posts
(inside container):

docker exec -it <container_id> bash
python manage.py parse_news --type=docker

Default admin panel credentials:

  • username: admin
  • password: adminpass

Or you can install locally

Ensure you have Python >= 3.8.12

  1. python -m venv venv Make venv
  2. source /venv/bin/activate Activate venv
  3. cd djnews && pip install -r requirements.txt Install required packages
  4. edit settings.py to fit your settings (DB, DEBUG, etc.) Fix your settings
  5. python manage.py makemigrations && python manage.py migrate Make migrations and migrate
  6. python manage.py parse_news Wait for parsing to complete
  7. python manage.py runserver Run server

API endpoints:

All news:

http://127.0.0.1:8000/news/

Filter by date:

http://127.0.0.1:8000/news/?date__exact=2022-8-25
http://127.0.0.1:8000/news/?date__gt=2022-8-25
http://127.0.0.1:8000/news/?date__lt=2022-8-25

Filter by tags:

http://127.0.0.1:8000/news/?tags=ozon?

Combined filtering:

http://127.0.0.1:8000/news/?tags=ozon?date__exact=2022-8-26