GithubHelp home page GithubHelp logo

pybites-open-source / youtube-infinite-scroll Goto Github PK

View Code? Open in Web Editor NEW
10.0 3.0 7.0 42.11 MB

License: MIT License

Makefile 3.94% Python 86.32% HTML 9.74%
youtube sqlmodel htmx selenium hacktoberfest hacktoberfest2021 vcr pytest

youtube-infinite-scroll's Introduction

YouTube infinite scroll

This demo uses SQLModel and htmx to generate an infinite scroll of videos of a YouTube videos.

Setup

Make a virtual environment and install the requirements:

$ make install
python3.9 -m venv venv && source venv/bin/activate && pip install -r requirements-dev.txt

Then go to Google Cloud Platform > YouTube Data API v3 and hit the blue ENABLE button, then generate your API key:

enable the API

create an API key

Next set up your .env file:

cp .env-example .env

Populate it with the following environment variables:

  • YT_CHANNEL: the YouTube channel to use this on, to try it out with PyBites you can use UCBn-uKDGsRBfcB0lQeOB_gA or for PyCon use UCMjMBMGt0WJQLeluw6qNJuA (demo below).

  • YOUTUBE_API_KEY: the API key you just created.

  • DATABASE_URL: create a database and point to it (in case of sqlite all you need to do is specify one like this: sqlite:///db.sqlite3)

Next let's cache the YouTube channel's data (all videos' metadata) to not exhaust the YouTube API rate limit.

Run the following command with your virtual environment enabled (this example uses PyCon's YouTube channel):

$ make dbsetup
source venv/bin/activate && python -m youtube.db
Total records: 172 (newly inserted: 172)

Result:

youtube-import.mp4

Lastly run the app:

make run

Navigate to localhost:8000 and you should see something like this:

inifnite-scroll.mp4

Testing

There are unit and functional tests for this project.

The unit tests use "cassettes" (cached API responses) so they are fast:

yi-infinite-scroll-unit-test.mp4

The functional (end-to-end) test uses the real DB that is configured in .env and Selenium to scroll to the bottom of the infinite scroll, then compare the amount of table rows on the page vs the amount of entries in the DB. This test requires FastAPI to be running.

So in terminal 1 run:

make run

Then in terminal 2 run the test:

yi-infinite-scroll-functional-test.cmproj.mp4

Of course you can also run all tests in one go with make test.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.