themrinalsinha / fampay-assignment

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fampay (Backend Assignment)

Available Commands

Pre-requisite: docker, docker-compose & make

  • To run the application
    $ make
  • To run django shell
    $ make shell
  • To run migrations and migrate
    $ make syncdb
  • To open db shell
    $ make psql

Local application setup

  • To run all the application
    $ make
  • once the application is up and running, in another shell run
    $ make syncdb
    It will run and apply all the database migration
  • Then, we'll create a superuser, just run
    $ make user
    
    it will create a superuser user username (admin) and password (admin).
  • Login to admin panel, goto http://127.0.0.1:9090/admin/
  • Under YT_APP there is Key Manager just your YouTube access key there.
  • The system will pick the keys from here and use to data polling
  • Done!

Observation

  • Under CELERY RESULTS > Task Results you can see what is the task status
  • Default search params and frequency
    SEARCH_QUERY=bitcoin # default
    QUERY_PER_PAGE=20
    REFRESH_FREQUENCY=30 # 30 second frequency
    you can override these settings by adding environment variables in docker-compose.yml or local.env

APIs

  • List API
    http://127.0.0.1:9090/api/v1/list/
    
    {
      "count": 120,
      "next": "http://127.0.0.1:9090/api/v1/list/?limit=10&offset=10",
      "previous": null,
      "results": [
          ... data
      ]
    }
  • Search Filter (works on title and description)
    http://127.0.0.1:9090/api/v1/list/?search=bitcoin%20death
    
    {
      "count": 3,
      "next": null,
      "previous": null,
      "results": [
          ... data
      ]
    }

Basic Requirements

  • Server should call the YouTube API continuously in background (async) which some intervals (say 10 seconds) for fetching the latest videos for a predefined search query and should store the data of videos (specifically these fields - Video title, description, publishing datetime, thumbnails URLs and any other fields you require) in a database with proper indexes.
  • A GET API which returns the stored video data in a paginated response sorted in descending order of published datetime.
  • A basic search API to search the stored videos using their title and description.
  • Dockerize the project.
  • It should be scalable and optimised.

Bonus Points

  • Add support for supplying multiple API keys so that if quota is exhausted on one, it automatically uses the next available key.
  • Make a dashboard to view the stored videos with filters and sorting options (optional) NOTE Implemented using django admin
  • Optimise search api, so that it's able to search videos containing partial match for the search query in either video title or description.

About


Languages

Language:Python 91.5%Language:Makefile 3.7%Language:Shell 3.5%Language:Dockerfile 1.3%