Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
The script I use to set up a new course, along with a synchronized repo on GitHub for use with "gitautopush"
#!/usr/bin/env python3
import argparse
import shutil
import os
from github import Github
github_token = open('/Users/reuven/.github_token').read().strip()
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--source', default='generic')
parser.add_argument('-d', '--date', required=True)
parser.add_argument('-c', '--client', required=True)
parser.add_argument('-r', '--repo', required=True)
parser.add_argument('-n', '--name', default='')
args = parser.parse_args()
suffix = f'-{}'
suffix = ''
destination = f'{args.client}-{}{suffix}'
print(f'Copying from "{args.source}" to "{destination}"')
shutil.copytree(args.source, destination)
os.rename(f'{destination}/Course notebook.ipynb',
f'{destination}/{args.client} - {}{suffix}.ipynb')
remote_info = f"""
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url ={args.repo}.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
remote = origin
merge = refs/heads/main
# Write the remote info to the Git configuration file
with open(f'{destination}/.git/config', 'w') as outfile:
# Create the repo on GitHub
g = Github(github_token)
user = g.get_user()
repo = user.create_repo(args.repo)
Copy link

reuven commented Apr 19, 2021

Note that this script assumes that there's a "generic" directory that (a) contains a Jupyter notebook and (b) has already been initialized as a Git repository. Using this program saves me 5-10 minutes for each class I teach — which, on the days I teach 4-5 different 2-hour classes, is a big win.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment