pydocker-cli

pydocker-cli starter project.


Table of Contents


Famed Contributors

@dennislwm

Hypothesis

pydocker-cli was a personal project to:

  • make lots of half-baked tiny python command line apps

Project Structure

 pydocker-cli/                                <-- Root of your project
   |- .gitignore                              <-- Git ignore file
   |- CONTRIBUTING.md                         <-- Contributing guide
   |- README.md                               <-- This README markdown file
   +- .github/                                <-- Root of GitHub templates, workflows, actions
      +- workflows/                           <-- Source files for GitHub workflows
   +- biblia/                                 <-- Source files for bible data
   +- etfdata/                                <-- Source files for ETF and stock data
   +- htmltopdf/                              <-- Source files for Html link to PDF conversion
   +- textscore/                              <-- Source files for text readability score
   +- udemyenrol/                             <-- Source files for Udemy free course
      |- .dockerignore                        <-- Docker ignore file
      |- actions.yml                          <-- GitHub actions file
      |- app.py                               <-- Tiny Python app
      |- Dockerfile                           <-- Dockerfile for app
      |- requirements.txt                     <-- Tiny Python app dependencies
      |- udemyenrol.md                        <-- Daily Free Udemy Courses published by GitHub Actions

Methodology

This is the minimum viable product (MVP) to test the above hypothesis.

Non-existant viable feature

  • make lots of half-baked tiny python command line apps
  • enable Dockerfile WORKDIR support for GitHub Actions (see Issue #4)

Existing viable feature

  • send email from Gmail using smtplib (Rade2020)
  • continuous deployment of tiny python apps using GitHub Actions (Mezz2020)

Complexity

Count the cost of complexity, i.e. incremental reward and risk reduction, before evolving MVP.

  • The cost of Click is quite high, ~150 lines of code in etfdata, for a shell file that has EMPTY functions (exclude tests).

Non-existant bloat

  • Nil

Existing bloat

  • use Click to to create and test a Python CLI app (Bowm2020), (Ppro2020)

1. etfdata

This tiny app prints etf and stock data.

1.1 Usage

$ python3 etfdata.py
Usage: etfdata.py [OPTIONS] COMMAND [ARGS]...

  This script prints etf and stock data

Options:
  -o, --out [csv|json|markdown|text]
                                  Output type, default=text
  -h, --help                      Show this message and exit.

Commands:
  cal    Economic calendar
  etf    ETF fundamentals
  list   List of symbols
  news   Latest market news
  stock  Stock fundamentals of SYMBOLS where SYMBOLS is one or more...

1.2 Configuration

etfdata requires a config.json to run correctly. This file contains sensitive information, hence it is not checked into repo.

Create a new file config.json in the same folder as etfdata.py and copy and paste below.

{
  "FINNHUB_API_KEY": "asdfasdfasdfasfasdfasdf",
  "FINNHUB_API_KEY_SANDBOX": "sandbox_asdfasdfasdfsadfasfdsaf"
}

Go to Finnhub Stock API to create a free account. Then copy and paste both of the above api keys.

1.3 References


2. htmltopdf

This tiny app does what its name suggests.


3. udemyenrol

This tiny app is invoked by GitHub Actions daily.

3.1 Nothing to do

The action file runs this Python app that updates this page at UTC 0:01 daily. You can bookmark this page to save thousands of dollars for Udemy courses every year (legally).

Daily Free Udemy Courses

3.2 Fork this repository if you want to receive email

If you want to receive this page in your email, fork this repository. In your forked repository, add these to the GitHub secrets:

  GMAIL: user@gmail.com
  GMAIL_APP_PASSWORD: generatedpassword

The app uses GMAIL to send both from (sender) and to (recepient). Go to Gmail account to create GMAIL_APP_PASSWORD.

Warning: Do not use your Gmail password for the app password, which is a special password that is used to bypass two-factor authentication.

3.3 Configuration (only if you are Contributing)

Udemyenrol requires a settings.yaml to run in your local development. This file contains sensitive information, hence it is not checked into repo.

Create a new file settings.yaml in the same folder as app.py and copy and paste below.

udemy:
  email: "name@example.com" 
  password: "password123" 
  gmail: "name@gmail.com"
  gmail_app_password: "generatedpassword"

This is an explanation of the above settings file.

  • email - Enter your Udemy registered email here (You do not need to change this as it is Disabled)
  • password - Enter your Udemy password here (You do not need to change this as it is Disabled)
  • gmail - Gmail address that is used by app to send daily free courses from and to
  • gmail_app_password - Gmail app password (Go to https://myaccount.google.com/apppasswords to generate one)

3.4 References


4. textscore

This tiny app generates a readability score from a file.

4.1 Usage

$ python3 textscore.py --help
Usage: textscore.py [OPTIONS] TEXTFILE

  This script scores the readability of a TEXTFILE

  TEXTFILE may include wildcards, e.g. *.txt

Options:
  -o, --out [csv|json|markdown|text]
                                  Output type, default=text
  -h, --help                      Show this message and exit.

4.2 References


5. biblia

This tiny app prints bible data from Biblia.

5.1 Usage

$ python3 biblia.py --help
Usage: biblia.py [OPTIONS] COMMAND [ARGS]...

  This script prints bible data

Options:
  -o, --out [csv|json|markdown|text]
                                  Output type, default=text
  -h, --help                      Show this message and exit.

Commands:
  content  Returns the content of a bible
  search   Searches the text of a bible
  toc      Returns the table of contents of a bible
  votd     Returns a carefully chosen verse each day

5.1 References


Local Workstation

Requirements

  • git
  • pipenv

Making code changes locally

  1. Clone the repository to your local workstation with git clone.

  2. Change directory to the cloned repo and project, e.g. cd pydocker-cli/udemyenrol.

  3. Create a Python virtual environment with pipenv shell.

  4. Install the Python dependencies with pipenv install.

  5. Start coding!


Common

Issue #4

  • This is a solution to enable Dockerfile WORKDIR support for GitHub Actions:
    • In main.yml, set both steps.with.entrypoint and steps.with.args values in combination with steps.uses, to overwrite ENTRYPOINT and CMD in your Dockerfile respectively
      • For example, set steps.with.entrypoint and steps.with.args to "python3" and "udemyenrol/app.py" respectively
    • Why? In Dockerfile, GitHub Actions (GA) sets its source folder to GITHUB_WORKSPACE, ie. root folder.
      • For example, when using commands COPY or ADD, it copies or adds from GITHUB_WORKSPACE instead of current folder (see structure below)
     GITHUB_WORKSPACE/                            <-- Root of your repository
       +- udemyenrol/                             <-- Current folder for Dockerfile
          |- Dockerfile                           <-- In Dockerfile, "COPY . ." copies from GITHUB_WORKSPACE instead of current folder
  • We tried THREE (3) workarounds that failed:
    • In Dockerfile, Github Actions ignores WORKDIR command
    • In main.yml, steps.working-directory does not work in combination with steps.uses
    • In actions.yml, run.steps.working-directory does not work in combination with runs.using: docker
  • Avoid using two separate Dockerfiles, one for GitHub Actions and one for local development.

Contributing

Please read the contributing guide on how you can actively participate in the development of this repository.


Reach Out!

Please consider giving this repository a star on GitHub.