├── PythonGists.egg-info ├── PKG-INFO ├── SOURCES.txt ├── dependency_links.txt ├── not-zip-safe ├── pbr.json ├── requires.txt └── top_level.txt ├── PythonGists ├── __init__.py ├── __init__.pyc ├── __pycache__ │ ├── __init__.cpython-34.pyc │ ├── access.cpython-34.pyc │ ├── generateRandomNote.cpython-34.pyc │ ├── gist.cpython-34.pyc │ └── github_auth.cpython-34.pyc ├── access.py ├── access.pyc ├── generateRandomNote.py ├── generateRandomNote.pyc ├── gist.py └── gist.pyc ├── README.md ├── demo.py ├── dist ├── PythonGists-1.0.0.zip ├── PythonGists-1.0.3.tar.gz ├── PythonGists-1.0.3.zip ├── PythonGists-1.0.4.tar.gz ├── PythonGists-1.1.1.tar.gz ├── PythonGists-1.1.2.tar.gz ├── PythonGists-1.1.3.tar.gz └── PythonGists-1.1.tar.gz └── setup.py /PythonGists.egg-info/PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 1.1 2 | Name: PythonGists 3 | Version: 1.1.3 4 | Summary: A Python Module to create and access GitHub Gists 5 | Home-page: https://github.com/geekpradd/PythonGists 6 | Author: Pradipta Bora 7 | Author-email: pradd@outlook.com 8 | License: MIT 9 | Description: PythonGists: A Python Module to create and access GitHub Gists 10 | -------------------------------------------------------------- 11 | 12 | PythonGists is a Python 2/3 module to create, view and access data from 13 | GitHub Gists. It uses requests and oauth to function and is based on the 14 | GitHub v3 API. 15 | 16 | Why PythonGists? 17 | ~~~~~~~~~~~~~~~~ 18 | 19 | There are numerous Python modules available for the GitHub v3 API but 20 | PythonGists is different. For starters, it is aimed only at the Gists 21 | part of the GitHub API and not the entire API. And it will never feature 22 | non Gists part of the GitHub API. 23 | 24 | So you might be thinking that you could have used python3-github or any 25 | other module for Gists. Technically, you could but PythonGistss is more 26 | specific. In Systems where saving even a tiny amount of space matters 27 | (like your VPS), PythonGistss will take less space and do the same 28 | (provided you only want GitHub Gists Access). 29 | 30 | Note 31 | ~~~~ 32 | 33 | This module is not to be confused with PyGist which is just a CLI. This 34 | is a python module (actually I would have picked up a different name if 35 | I knew about that module) 36 | 37 | Installation 38 | ~~~~~~~~~~~~ 39 | 40 | Installation is done through PIP: 41 | 42 | :: 43 | 44 | pip install PythonGists 45 | 46 | Usage 47 | ~~~~~ 48 | 49 | You can use PythonGists either by signing into GitHub or anonymously. 50 | Note that the syntax for logged in usage and anonymous usage is 51 | different. Here are some demos: 52 | 53 | Create Gist Anonymously 54 | ''''''''''''''''''''''' 55 | 56 | .. code:: python 57 | 58 | from PythonGists import PythonGists 59 | link = PythonGists.Gist(description='a sample gist',content='Hey GitHub',name='demo.txt') 60 | 61 | print("The link is {0}".format(link)) 62 | 63 | Create Gist as a logged in user 64 | ''''''''''''''''''''''''''''''' 65 | 66 | .. code:: python 67 | 68 | from PythonGists import PythonGists 69 | gistObject=PythonGists(username='youruser',password='somepass') 70 | print(gistObject.createGist(description='a sample gist',content='Hey GitHub',name='demo.txt')) 71 | 'This will print the link' 72 | 73 | Create Gist from File Anonymously 74 | ''''''''''''''''''''''''''''''''' 75 | 76 | .. code:: python 77 | 78 | from PythonGists import PythonGists 79 | link = PythonGists.GistFromFile(description='a sample gist',file='demo.py') 80 | 81 | print("The link is {0}".format(link)) 82 | 83 | Create Gist from File (logged in) 84 | ''''''''''''''''''''''''''''''''' 85 | 86 | .. code:: python 87 | 88 | from PythonGists import PythonGists 89 | gistObject=PythonGists(username='youruser',password='somepass') 90 | print(gistObject.createGistFromFile(description='a sample gist',file='demo.py')) 91 | 'This will print the link' 92 | 93 | Get User Gists Links (same for both) 94 | '''''''''''''''''''''''''''''''''''' 95 | 96 | Here just replace GitHubGist in the print line with your gistObject for 97 | logged in users. 98 | 99 | .. code:: python 100 | 101 | from PythonGists import PythonGists 102 | print(PythonGists.getGistsLinks('geekpradd')) 103 | 104 | Get User Gists Data (same for both) 105 | ''''''''''''''''''''''''''''''''''' 106 | 107 | Here just replace GitHubGist in the print line with your gistObject for 108 | logged in users. 109 | 110 | .. code:: python 111 | 112 | from PythonGists import PythonGists 113 | gistArray = PythonGists.getGistsData('geekpradd') 114 | 115 | Note that gistArray will contain objects of the Gist Class which has 116 | access to the Gist data. Now, I'll show you how to access Gist data from 117 | the Gist Object. 118 | 119 | Get Single Gist Data 120 | '''''''''''''''''''' 121 | 122 | ``python from PythonGists import Gist gistObj = Gist('https://gist.github.com/geekpradd/a3e7a590887cf7bbf161') print (gistObj.getFileContent()) #Will retutn a Dictionary with keys = File names and values = file content`` 123 | 124 | About 125 | ~~~~~ 126 | 127 | This module is created by Pradipta (geekpradd) using the GitHub API and 128 | requests. 129 | 130 | Platform: UNKNOWN 131 | Classifier: Development Status :: 4 - Beta 132 | Classifier: Topic :: Utilities 133 | Classifier: License :: OSI Approved :: MIT License 134 | Classifier: Operating System :: OS Independent 135 | Classifier: Programming Language :: Python 136 | -------------------------------------------------------------------------------- /PythonGists.egg-info/SOURCES.txt: -------------------------------------------------------------------------------- 1 | setup.py 2 | PythonGists/__init__.py 3 | PythonGists/access.py 4 | PythonGists/generateRandomNote.py 5 | PythonGists/gist.py 6 | PythonGists.egg-info/PKG-INFO 7 | PythonGists.egg-info/SOURCES.txt 8 | PythonGists.egg-info/dependency_links.txt 9 | PythonGists.egg-info/not-zip-safe 10 | PythonGists.egg-info/pbr.json 11 | PythonGists.egg-info/requires.txt 12 | PythonGists.egg-info/top_level.txt -------------------------------------------------------------------------------- /PythonGists.egg-info/dependency_links.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /PythonGists.egg-info/not-zip-safe: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /PythonGists.egg-info/pbr.json: -------------------------------------------------------------------------------- 1 | {"is_release": false, "git_version": "29e8c8f"} -------------------------------------------------------------------------------- /PythonGists.egg-info/requires.txt: -------------------------------------------------------------------------------- 1 | requests -------------------------------------------------------------------------------- /PythonGists.egg-info/top_level.txt: -------------------------------------------------------------------------------- 1 | PythonGists 2 | -------------------------------------------------------------------------------- /PythonGists/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = 'Pradipta Bora' 2 | __ver__ = '1.0.0' 3 | try: 4 | from .gist import * 5 | except: 6 | from gist import * -------------------------------------------------------------------------------- /PythonGists/__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geekpradd/PythonGists/af44014cd700595522e7296ed7ffafc101ea070e/PythonGists/__init__.pyc -------------------------------------------------------------------------------- /PythonGists/__pycache__/__init__.cpython-34.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geekpradd/PythonGists/af44014cd700595522e7296ed7ffafc101ea070e/PythonGists/__pycache__/__init__.cpython-34.pyc -------------------------------------------------------------------------------- /PythonGists/__pycache__/access.cpython-34.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geekpradd/PythonGists/af44014cd700595522e7296ed7ffafc101ea070e/PythonGists/__pycache__/access.cpython-34.pyc -------------------------------------------------------------------------------- /PythonGists/__pycache__/generateRandomNote.cpython-34.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geekpradd/PythonGists/af44014cd700595522e7296ed7ffafc101ea070e/PythonGists/__pycache__/generateRandomNote.cpython-34.pyc -------------------------------------------------------------------------------- /PythonGists/__pycache__/gist.cpython-34.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geekpradd/PythonGists/af44014cd700595522e7296ed7ffafc101ea070e/PythonGists/__pycache__/gist.cpython-34.pyc -------------------------------------------------------------------------------- /PythonGists/__pycache__/github_auth.cpython-34.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geekpradd/PythonGists/af44014cd700595522e7296ed7ffafc101ea070e/PythonGists/__pycache__/github_auth.cpython-34.pyc -------------------------------------------------------------------------------- /PythonGists/access.py: -------------------------------------------------------------------------------- 1 | GITHUB_API = 'https://api.github.com' 2 | 3 | 4 | import requests 5 | import getpass 6 | import json 7 | try: 8 | from .generateRandomNote import noteGen 9 | except: 10 | from generateRandomNote import noteGen 11 | 12 | def main(username,password): 13 | username = username 14 | password = password 15 | note=noteGen() 16 | url =GITHUB_API+ '/authorizations' 17 | payload = {"scopes":["gist"]} 18 | if note: 19 | payload['note'] = note 20 | res = requests.post( 21 | url, 22 | auth = (username, password), 23 | data = json.dumps(payload), 24 | ) 25 | j = json.loads(res.text) 26 | if res.status_code >= 400: 27 | msg = j.get('message', 'UNDEFINED ERROR (no error description from server)') 28 | print(j) 29 | print ('ERROR: %s' % msg) 30 | return None 31 | 32 | token = j['token'] 33 | 34 | return token 35 | 36 | if __name__ == '__main__': 37 | username=input('username: ') 38 | password=getpass.getpass('password: ') 39 | main(username,password) -------------------------------------------------------------------------------- /PythonGists/access.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geekpradd/PythonGists/af44014cd700595522e7296ed7ffafc101ea070e/PythonGists/access.pyc -------------------------------------------------------------------------------- /PythonGists/generateRandomNote.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | firstWord=['admin','python','ruby','github','jquery','AJAX','login','data','java','php'] 4 | secondWord=['client','script','code','game','API','program','tutorial','description0','embed','sharer'] 5 | 6 | def noteGen(): 7 | return firstWord[randint(0,9)] + ' ' + secondWord[randint(0,9)] 8 | 9 | if __name__=='__main__': 10 | print (noteGen()) -------------------------------------------------------------------------------- /PythonGists/generateRandomNote.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geekpradd/PythonGists/af44014cd700595522e7296ed7ffafc101ea070e/PythonGists/generateRandomNote.pyc -------------------------------------------------------------------------------- /PythonGists/gist.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | try: 4 | import simplejson as json 5 | except ImportError: 6 | import json 7 | try: 8 | from .access import main as login 9 | 10 | except: 11 | from access import main as login 12 | 13 | API_URL='https://api.github.com' 14 | 15 | class Gist(object): 16 | def __init__(self,url): 17 | self.gistUrl = url 18 | self.gistId = url.split('/')[-1] 19 | def __repr__(self): 20 | return ''.format(self.gistUrl) 21 | def getRawJSON(self): 22 | return requests.get('{0}/gists/{1}'.format(API_URL,self.gistId)).json() 23 | def getFileContent(self): 24 | files = self.getRawJSON()['files'] 25 | return dict([(key,files[key]['content']) for key in files.keys()]) 26 | 27 | class PythonGists(object): 28 | def __init__(self,username,password): 29 | self.accessToken=login(username,password) 30 | 31 | @staticmethod 32 | def Gist(description,content,name,token=None): 33 | public=True 34 | url=API_URL+'/gists' 35 | 36 | if token is None: 37 | authtoken=None 38 | else: 39 | authtoken=token 40 | token='token {0}'.format(authtoken) 41 | data=json.dumps({"description":description,"public":public,"files":{name:{"content":content}}}) 42 | 43 | if authtoken is None: 44 | r=requests.post(url,data=data) 45 | else: 46 | r=requests.post(url,headers={'Authorization':token},data=data) 47 | 48 | uniqueID=r.json()['url'] 49 | gistLink="http://gist.github.com/{0}".format(uniqueID.split('/')[-1]) 50 | return gistLink 51 | @staticmethod 52 | def GistFromFile(description,file): 53 | with open(file,'r') as f: 54 | content=f.read() 55 | return PythonGists.Gist(description,content,file) 56 | def createGist(self,description,content,name): 57 | return self.Gist(description,content,name,self.accessToken) 58 | def createGistFromFile(self,description,file): 59 | with open(file,'r') as f: 60 | content=f.read() 61 | return self.Gist(description,content,file,self.accessToken) 62 | @staticmethod 63 | def getGistsLinks(username): 64 | url='{0}/users/{1}/gists'.format(API_URL,username) 65 | data=requests.get(url).json() 66 | return [a['url'] for a in data] 67 | @staticmethod 68 | def getGists(username): 69 | url='{0}/users/{1}/gists'.format(API_URL,username) 70 | data=requests.get(url).json() 71 | return [Gist(a['url']) for a in data] 72 | 73 | if __name__=='__main__': 74 | 75 | print('Welcome to PythonGists. Please check out the docs first at GitHub and then use') 76 | 77 | -------------------------------------------------------------------------------- /PythonGists/gist.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geekpradd/PythonGists/af44014cd700595522e7296ed7ffafc101ea070e/PythonGists/gist.pyc -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## PythonGists: A Python Module to create and access GitHub Gists 2 | 3 | PythonGists is a Python 2/3 module to create, view and access data from GitHub Gists. It uses requests and oauth to function and is based on the GitHub v3 API. 4 | 5 | ### Why PythonGists? 6 | 7 | There are numerous Python modules available for the GitHub v3 API but PythonGists is different. For starters, it is aimed only at the Gists part of the GitHub API and not the entire API. And it will never feature non Gists part of the GitHub API. 8 | 9 | So you might be thinking that you could have used python3-github or any other module for Gists. Technically, you could but PythonGistss is more specific. In Systems where saving even a tiny amount of space matters (like your VPS), PythonGistss will take less space and do the same (provided you only want GitHub Gists Access). 10 | 11 | ### Note 12 | 13 | This module is not to be confused with PyGist which is just a CLI. This is a python module (actually I would have picked up a different name if I knew about that module) 14 | 15 | ### Installation 16 | 17 | Installation is done through PIP: 18 | 19 | ``` 20 | pip install PythonGists 21 | ``` 22 | 23 | ### Usage 24 | 25 | You can use PythonGists either by signing into GitHub or anonymously. Note that the syntax for logged in usage and anonymous usage is different. Here are some demos: 26 | 27 | ##### Create Gist Anonymously 28 | 29 | ```python 30 | from PythonGists import PythonGists 31 | link = PythonGists.Gist(description='a sample gist',content='Hey GitHub',name='demo.txt') 32 | 33 | print("The link is {0}".format(link)) 34 | ``` 35 | 36 | ##### Create Gist as a logged in user 37 | 38 | ```python 39 | from PythonGists import PythonGists 40 | gistObject=PythonGists(username='youruser',password='somepass') 41 | print(gistObject.createGist(description='a sample gist',content='Hey GitHub',name='demo.txt')) 42 | 'This will print the link' 43 | ``` 44 | ##### Create Gist from File Anonymously 45 | 46 | ```python 47 | from PythonGists import PythonGists 48 | link = PythonGists.GistFromFile(description='a sample gist',file='demo.py') 49 | 50 | print("The link is {0}".format(link)) 51 | ``` 52 | 53 | ##### Create Gist from File (logged in) 54 | 55 | ```python 56 | from PythonGists import PythonGists 57 | gistObject=PythonGists(username='youruser',password='somepass') 58 | print(gistObject.createGistFromFile(description='a sample gist',file='demo.py')) 59 | 'This will print the link' 60 | ``` 61 | ##### Get User Gists Links (same for both) 62 | 63 | Here just replace GitHubGist in the print line with your gistObject for logged in users. 64 | 65 | ```python 66 | from PythonGists import PythonGists 67 | print(PythonGists.getGistsLinks('geekpradd')) 68 | ``` 69 | 70 | ##### Get User Gists Data (same for both) 71 | 72 | Here just replace GitHubGist in the print line with your gistObject for logged in users. 73 | 74 | ```python 75 | from PythonGists import PythonGists 76 | gistArray = PythonGists.getGistsData('geekpradd') 77 | ``` 78 | 79 | Note that gistArray will contain objects of the Gist Class which has access to the Gist data. Now, I'll show you how to access Gist data from the Gist Object. 80 | 81 | ##### Get Single Gist Data 82 | 83 | ```python 84 | from PythonGists import Gist 85 | gistObj = Gist('https://gist.github.com/geekpradd/a3e7a590887cf7bbf161') 86 | print (gistObj.getFileContent()) #Will retutn a Dictionary with keys = File names and values = file content 87 | ``` 88 | 89 | ### About 90 | 91 | This module is created by Pradipta (geekpradd) using the GitHub API and requests. 92 | -------------------------------------------------------------------------------- /demo.py: -------------------------------------------------------------------------------- 1 | from PythonGists import GitHubGist 2 | 3 | print(GitHubGist.getGistsLinks(username='geekpradd')) -------------------------------------------------------------------------------- /dist/PythonGists-1.0.0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geekpradd/PythonGists/af44014cd700595522e7296ed7ffafc101ea070e/dist/PythonGists-1.0.0.zip -------------------------------------------------------------------------------- /dist/PythonGists-1.0.3.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geekpradd/PythonGists/af44014cd700595522e7296ed7ffafc101ea070e/dist/PythonGists-1.0.3.tar.gz -------------------------------------------------------------------------------- /dist/PythonGists-1.0.3.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geekpradd/PythonGists/af44014cd700595522e7296ed7ffafc101ea070e/dist/PythonGists-1.0.3.zip -------------------------------------------------------------------------------- /dist/PythonGists-1.0.4.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geekpradd/PythonGists/af44014cd700595522e7296ed7ffafc101ea070e/dist/PythonGists-1.0.4.tar.gz -------------------------------------------------------------------------------- /dist/PythonGists-1.1.1.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geekpradd/PythonGists/af44014cd700595522e7296ed7ffafc101ea070e/dist/PythonGists-1.1.1.tar.gz -------------------------------------------------------------------------------- /dist/PythonGists-1.1.2.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geekpradd/PythonGists/af44014cd700595522e7296ed7ffafc101ea070e/dist/PythonGists-1.1.2.tar.gz -------------------------------------------------------------------------------- /dist/PythonGists-1.1.3.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geekpradd/PythonGists/af44014cd700595522e7296ed7ffafc101ea070e/dist/PythonGists-1.1.3.tar.gz -------------------------------------------------------------------------------- /dist/PythonGists-1.1.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geekpradd/PythonGists/af44014cd700595522e7296ed7ffafc101ea070e/dist/PythonGists-1.1.tar.gz -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | try: 4 | import pypandoc 5 | description=pypandoc.convert('README.md','rst') 6 | except: 7 | description='' 8 | setup(name='PythonGists', 9 | version="1.1.3", 10 | description='A Python Module to create and access GitHub Gists', 11 | long_description=description, 12 | url='https://github.com/geekpradd/PythonGists', 13 | author='Pradipta Bora', 14 | author_email='pradd@outlook.com', 15 | license='MIT', 16 | packages=['PythonGists'], 17 | install_requires=[ 18 | 'requests' ], 19 | classifiers=[ 20 | "Development Status :: 4 - Beta", 21 | "Topic :: Utilities", 22 | "License :: OSI Approved :: MIT License", 23 | "Operating System :: OS Independent", 24 | "Programming Language :: Python" 25 | ], 26 | zip_safe=False) 27 | --------------------------------------------------------------------------------