Skip to content

Instantly share code, notes, and snippets.

@maphew
Forked from anonymous/push_to_Gist.txt
Last active April 19, 2020 16:34

Revisions

  1. maphew renamed this gist May 2, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. maphew revised this gist May 2, 2013. 1 changed file with 15 additions and 5 deletions.
    20 changes: 15 additions & 5 deletions Push to Gist
    Original file line number Diff line number Diff line change
    @@ -8,8 +8,8 @@ content = p.b # node body

    api_url = 'https://api.github.com/gists'

    user = 'anonymous' # todo: derive from... parent node? leoID?
    password = '' # todo: derive from... tricky one. ssh key I 'spose
    user = '' # todo: derive from... parent node? leoID?
    password = '' # todo: derive from... ???


    g.es(filename)
    @@ -24,9 +24,19 @@ payload = {
    }

    #print (payload)
    r = requests.post(api_url, data=json.dumps(payload), auth=(user, password))
    #r = requests.post(api_url, data=json.dumps(payload), auth=(user, password))
    r = requests.post(api_url, data=json.dumps(payload))
    print (r.status_code)
    print (r.text) #todo: capture in Leo for re-use later
    #print (r.text)

    c.createLastChildNode(self, parent, head, r.text) # broken
    # capture and save request results
    p = c.p
    nd = p.insertAsLastChild()
    nd.h = 'Push result: text'
    nd.b = r.text
    c.redraw()

    #todo: parse text result and return clickable urls

    # c.createLastChildNode(p.h, 'testing...', r.text)

  3. maphew revised this gist May 2, 2013. 2 changed files with 32 additions and 24 deletions.
    32 changes: 32 additions & 0 deletions Push to Gist
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    import requests
    import json

    description = "published from Leo" # todo: derive from docstring, if present, otherwise 1st para
    public = True
    filename = p.h # node headline
    content = p.b # node body

    api_url = 'https://api.github.com/gists'

    user = 'anonymous' # todo: derive from... parent node? leoID?
    password = '' # todo: derive from... tricky one. ssh key I 'spose


    g.es(filename)
    print('\n\n--- %s ---' % filename)

    payload = {
    'description': description,
    'public': public,
    'files': {
    filename: {'content': content}
    }
    }

    #print (payload)
    r = requests.post(api_url, data=json.dumps(payload), auth=(user, password))
    print (r.status_code)
    print (r.text) #todo: capture in Leo for re-use later

    c.createLastChildNode(self, parent, head, r.text) # broken

    24 changes: 0 additions & 24 deletions push_to_Gist.txt
    Original file line number Diff line number Diff line change
    @@ -1,24 +0,0 @@
    import requests
    import json

    tmp = g.os.environ['TEMP']

    description = "published from Leo"
    public = True
    filename = p.h # node headline
    content = p.b # node body

    g.es(filename)
    print('\n\n--- %s ---' % filename)
    payload = {
    'description': description,
    'public': public,
    'files': {
    filename: {'content': content}
    }
    }

    print (payload)
    r = requests.post('https://api.github.com/gists', data=json.dumps(payload))
    print (r.status_code)
    print (r.text)
  4. @invalid-email-address Anonymous created this gist May 2, 2013.
    24 changes: 24 additions & 0 deletions push_to_Gist.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    import requests
    import json

    tmp = g.os.environ['TEMP']

    description = "published from Leo"
    public = True
    filename = p.h # node headline
    content = p.b # node body

    g.es(filename)
    print('\n\n--- %s ---' % filename)
    payload = {
    'description': description,
    'public': public,
    'files': {
    filename: {'content': content}
    }
    }

    print (payload)
    r = requests.post('https://api.github.com/gists', data=json.dumps(payload))
    print (r.status_code)
    print (r.text)