Git Product home page Git Product logo

Comments (3)

jph00 avatar jph00 commented on July 22, 2024

This doesn't seem to be in the correct format for create gists - try doing a google search to find examples.

from ghapi.

tou55aint avatar tou55aint commented on July 22, 2024

This works.

import json
import requests

GITHUB_API="https://api.github.com"
API_TOKEN='yourtoken'

#form a request URL
url=GITHUB_API+"/gists"
print("Request URL: %s"%url)

headers ={
    'Authorization': 'token %s' % API_TOKEN
}

params = {
 'scope': 'gist'   
}

payload = {
    "description": "An algorithm that describes obtaining the width and length of an underwater water cistern.",
    "public": True,
    "files": {
        "cistern.txt": {"content": "A cistern.\nThe height is 3.33, and a volume of 27.78 has been excavated.\nThe length exceeds the width by 0.83.\nYou should take the reciprocal of the height, 3.33, obtaining 0.3.\nMultiplay this by the volume, 27.78, obtaining 8.33.\nTake half of 0.83 and square it, obtaining 0.17.\nAdd 8.33 and you get 8.51.\nThe square root is 2.92.\nMake two copies of this, adding to the one 0.42 and subtracting from the other.\nYou find that 3.33 is the length and 2.5 is the width.\nThisis the procedure." 
    }
  }
}

res = requests.post(url, headers=headers, params=params, data=json.dumps(payload))

from ghapi.

jph00 avatar jph00 commented on July 22, 2024

Here's how to do it in ghapi:

from ghapi.core import GhApi
gists = GhApi().gists
gist = gists.create("testing gist", public=True, files={"test.txt": {"content": "My content"}})
print(gist.html_url)
gists.delete(gist.id)

from ghapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.