Advertisement
Guest User

Untitled

a guest
Nov 3rd, 2016
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #!/usr/bin/env python
  2. """
  3. A CLI script to create a gist.
  4. """
  5. import argparse
  6. import os.path
  7. from github3 import login
  8.  
  9.  
  10. def create(username, password, files, desc="", public=True):
  11. gh = login(username, password)
  12. gist_files = {}
  13. for path in files:
  14. filename = os.path.basename(path)
  15. gist_files[filename] = {'content': file(path, 'r').read()}
  16. gist = gh.create_gist(desc, gist_files, public)
  17. print(gist.html_url)
  18.  
  19.  
  20. def main():
  21. parser = argparse.ArgumentParser(description='Create a gist.')
  22. username = parser.add_argument(
  23. '-u', '--username', required=True,
  24. help="The Github username to use.")
  25. password = parser.add_argument(
  26. '-p', '--password', required=True,
  27. help="The Github password or token to use.")
  28. desc = parser.add_argument(
  29. '-d', '--desc', type=str,
  30. help="The description for the gist.")
  31. public = parser.add_argument(
  32. '--public', default=True,
  33. help="Whether the gist should be public or not. Defaults to True.")
  34. files = parser.add_argument(
  35. '-f', '--files', nargs="+", required=True,
  36. help="The files to upload and add to the gist.")
  37. args = parser.parse_args()
  38. create(args.username, args.password, args.files, args.desc, args.public)
  39.  
  40.  
  41. if __name__ == "__main__":
  42. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement