pythongithubgistgithub3.py

Getting revisions data from Github gist


    gist_ids = 'abc'

    def main():
        gh = github3.login (
            token=os.environ.get('my_token'),
            url='  ')
        my_gist = gh.gist(gist_ids)

        resp = github3.gists.history.GistHistory( json, session=None)

        print json.dumps(resp)
   if __name__ == '__main__':
    main()

i am trying get the revision data form gist and store in the form of json.

New to python apis please light me folks

Error:

Traceback (most recent call last):
  File "push.py", line 51, in <module>
    main()
  File "push.py", line 26, in main
    resp = github3.gists.history.GistHistory( json, session=None)
NameError: global name 'json' is not defined

Solution

  • Depending on which version of github3.py you have installed you have two options:

    1. If you're using an alpha version of 1.0 you should use the commits() method on your my_gist object. (Documentation: http://github3.readthedocs.io/en/develop/gists.html)

    2. if you're using a 0.9 series version you should use the iter_commits() method on the same object. (Documentation: http://github3.readthedocs.io/en/stable/gists.html#github3.gists.gist.Gist.iter_commits)

    These will work roughly like this:

    # 1.0.0a4
    for gist_commit in my_gist.commits():
        # do stuff with previous version
    # 0.9.6
    for gist_commit in my_gist.iter_commits():
        # ...
    

    Alternatively

    # 1.0.0a4
    my_gist_history = list(my_gist.commits())
    # 0.9.6
    my_gist_history = list(my_gist.iter_commits())