Skip to main content

Repo Gist Sync

https://pypi.python.org/pypi/repo-gist-sync https://pypistats.org/packages/repo-gist-sync

A library to synchronize git repository to Github Gists

    graph TD;

    A(local machine)
    A -->|push| B(Github repository)
    B -->|Github Actions| C(Gists)
    B -->|Github Actions| E(Gists)
    B -->|Github Actions| F(Gists)
    C --> D(Embeds)
    E --> G(Embeds)
    F --> H(Embeds)
    C --> I(Embeds)
    E --> J(Embeds)
    F --> K(Embeds)

Installation

Install from PyPI.

pip install repo-gist-sync

Dependencies: requests, click

Example

  1. Write the Code as follows (in the repository, examples folder):
  • get_user_id.py
#-- title: Get User's ID
#-- description: Code to retrieve user_id from username
#-- tags: python, medium_api, medium_api_py


# Import libraries
import os
from medium_api import Medium

#%%
# Get RAPIDAPI_KEY from the environment
api_key = os.getenv('RAPIDAPI_KEY')

#%%
# Create a `Medium` Object
medium = Medium(api_key)

#%%
# Get the `User` Object using "username" and print ID
user = medium.user(username="nishu-jain")
print(user.user_id)
  • get_user_id_output.txt
1985b61817c3
  1. Sync using gistdirsync CLI tool (from local machine or via Github Actions).
gistdirsync --auth-token $GIST_TOKEN --directory /path/to/examples
  1. Resulting Gist looks like this.

[Get User's ID] Code to retrieve user_id from username #python #medium_api #medium_api_py

get_user_id.py

# Import libraries
import os
from medium_api import Medium

# Get RAPIDAPI_KEY from the environment
api_key = os.getenv('RAPIDAPI_KEY')

# Create a `Medium` Object
medium = Medium(api_key)

# Get the `User` Object using "username" and print ID
user = medium.user(username="nishu-jain")
print(user.user_id)

get_user_id_1.py

# Import libraries
import os
from medium_api import Medium

get_user_id_2.py

# Get RAPIDAPI_KEY from the environment
api_key = os.getenv('RAPIDAPI_KEY')

get_user_id_3.py

# Create a `Medium` Object
medium = Medium(api_key)

get_user_id_4.py

# Get the `User` Object using "username" and print ID
user = medium.user(username="nishu-jain")
print(user.user_id)

get_user_id_output.txt

1985b61817c3

Continuous Deployment with Github Actions

Note: You can generate the GIST_TOKEN in Github Settings and place it in "secrets" in repository's settings.

Place an YAML file under .github/workflow/repo-gist-sync.yml with the following content:

name: GIST CD on main branch and example directory change

on:
  push:
    paths:
      - examples/**

jobs:
  build:
    if: github.ref == 'refs/heads/main'

    runs-on: ubuntu-latest

    strategy:
      matrix:
        python-version: ['3.8']

    steps:
    - uses: actions/checkout@v2

    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}

    - name: Install repo-gist-sync
      run: pip install repo-gist-sync

    - name: Use "gistsyncdir" on "examples" directory
      run: gistdirsync --auth-token ${{ secrets.GIST_TOKEN }} --directory ./examples/

Note: Change directory name ("examples") as per required in the yaml file.

Features

  • Supports python (.py), javascrip (.js) and shellscripts (.sh)
  • In case of python and shellscripts, it can write metadata (title, description, & tags) for gists in code file itself (#--).
  • Break the code in smaller snippets using separator (#%%).
  • Can save the output in the corresponding gist by creating an additional file as "filename_output.txt"

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

repo_gist_sync-0.4.5.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

repo_gist_sync-0.4.5-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file repo_gist_sync-0.4.5.tar.gz.

File metadata

  • Download URL: repo_gist_sync-0.4.5.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.19

File hashes

Hashes for repo_gist_sync-0.4.5.tar.gz
Algorithm Hash digest
SHA256 757d29ee893dfdaf2537467081e1199c41a95399e9a1a13ae5c353aa34b67ae1
MD5 7a75a5f019390d8ca501f2782ca7b003
BLAKE2b-256 ba0b24cb46288be32cbbcb180a63a84baffb3c1785559d5a21d28df6cbaad97a

See more details on using hashes here.

File details

Details for the file repo_gist_sync-0.4.5-py3-none-any.whl.

File metadata

  • Download URL: repo_gist_sync-0.4.5-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.19

File hashes

Hashes for repo_gist_sync-0.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 b7670e7a27b5def8c0d956b5f5875c0dde97210968a30514e9d0c65d522750a0
MD5 82e627609730e23ff1b700c0e628c50d
BLAKE2b-256 8f0fd938c3d3103be8450888589944432f5fc1ac59afc3d51c6bb372de29b5f6

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.4.5 This release

2 files

0.4.4

2 files

0.4.3

1 file

0.4.2

2 files

0.4.1

2 files

0.4

2 files

0.3

2 files

0.2

2 files

0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page