Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- """
- A CLI script to create a gist.
- """
- import argparse
- import os.path
- from github3 import login
- def create(username, password, files, desc="", public=True):
- gh = login(username, password)
- gist_files = {}
- for path in files:
- filename = os.path.basename(path)
- gist_files[filename] = {'content': file(path, 'r').read()}
- gist = gh.create_gist(desc, gist_files, public)
- print(gist.html_url)
- def main():
- parser = argparse.ArgumentParser(description='Create a gist.')
- username = parser.add_argument(
- '-u', '--username', required=True,
- help="The Github username to use.")
- password = parser.add_argument(
- '-p', '--password', required=True,
- help="The Github password or token to use.")
- desc = parser.add_argument(
- '-d', '--desc', type=str,
- help="The description for the gist.")
- public = parser.add_argument(
- '--public', default=True,
- help="Whether the gist should be public or not. Defaults to True.")
- files = parser.add_argument(
- '-f', '--files', nargs="+", required=True,
- help="The files to upload and add to the gist.")
- args = parser.parse_args()
- create(args.username, args.password, args.files, args.desc, args.public)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement