Beispiel #1
0
def save_anonymous_gist(title, files):
    """
    October 21, 2015
    title = the gist title
    files = {
        'spam.txt' : {
            'content': 'What... is the air-speed velocity of an unladen swallow?'
            }
            # ..etc...
        }

    works also in blocks eg from
    https://gist.github.com/anonymous/b839e3a4d596b215296f
    to
    http://bl.ocks.org/anonymous/b839e3a4d596b215296f

    So we return 3 different urls

    """

    try:
        from github3 import create_gist
    except:
        print("github3 library not found (pip install github3)")
        raise SystemExit(1)

    gist = create_gist(title, files)

    urls = {
        'gist' : gist.html_url,
        'blocks' : "http://bl.ocks.org/anonymous/" + gist.html_url.split("/")[-1],
        'blocks_fullwin' : "http://bl.ocks.org/anonymous/raw/" + gist.html_url.split("/")[-1]
    }

    return urls
Beispiel #2
0
    def create_gist(self,
                    description=None,
                    files=(),
                    public=True,
                    anonymous=False,
                    short_url=False):
        """Create public, private or anonymous gists"""
        if description is None:
            description = ''

        if anonymous:
            from github3 import create_gist
            gist = create_gist(description, upload_files(files))
        else:
            gist = self.github.create_gist(description, upload_files(files), \
                    public)

        click.echo(url_shorten(gist.html_url) if short_url else gist.html_url)
Beispiel #3
0
def post_gist_github(geojson, auth, title):
    files = {
        'artists.geojson': {
            'content': geojson
        }
    }

    try:
        if not auth:
            gist = github3.create_gist(title, files)
        else:
            gist = auth.create_gist(title, files, public=False)
    except github3.GitHubError as e:
        msg = "Issue posting an anonymous Gist: {0}".format(e)
        raise GithubError(msg)

    gist_url = gist.html_url

    return gist_url
Beispiel #4
0
def gist_up(args):
    basename = os.path.basename(args.filename)
    files = {
        basename: {
            'content': read_file(args.filename)
        }
    }

    if args.user and args.passwd:
        gh = login(args.user, args.passwd)
        gist = gh.create_gist(args.description, files, public=args.private)
        return gist.html_url
    elif args.user and args.passwd and args.two-factor:
	gh = login(args.user, args.passwd, two_factor_callback=two_factor_function)
        gist = gh.create_gist(args.description, files, public=args.private)
        return gist.html_url

    else:  # Anonymous gist, public by default.
        gist = create_gist(args.description, files)
        return gist.html_url
Beispiel #5
0
def do_gist_post(imlabel, urlabel, textview, gist_name):
  scrn_dir = os.path.expanduser("~") + "/catcloud_scrns"
  if not os.path.exists(scrn_dir):
    os.makedirs(scrn_dir)
  txt_name = scrn_dir + "/" + str(time.time()).replace(".", "") + ".txt"
  txt2_name = str(time.time()).replace(".", "") + ".txt"
  imlabel.set_text(txt_name)
  tbuff = textview.get_buffer()
  outfile = open(txt_name, "w")
  outfile.write(tbuff.get_text(tbuff.get_start_iter(), tbuff.get_end_iter()))
  outfile.close()
  print "Posting gist..."
  files = {
    txt2_name : {
        'content': tbuff.get_text(tbuff.get_start_iter(), tbuff.get_end_iter())
        }
    }
  gist = create_gist(gist_name, files)
  print(gist.html_url)
  urlabel.set_text("Gist uploaded by url: " + gist.html_url)
  pyperclip.copy(gist.html_url)
 def test_create_gist(self):
     args = ('description', {'files': ['files']})
     github3.create_gist(*args)
     self.gh.create_gist.assert_called_with(*args)
Beispiel #7
0
 def test_create_gist(self):
     """Show that github3.create_gist proxies to GitHub."""
     args = ('description', {'files': ['file']})
     github3.create_gist(*args)
     self.gh.create_gist.assert_called_once_with(*args)
Beispiel #8
0
# https://github3py.readthedocs.org/en/master/examples/gist.html#creating-an-anonymous-gist

# >sudo pip install github3.py


from github3 import create_gist

files = {"spam.txt": {"content": "What... is the air-speed velocity of an unladen swallow?"}}
gist = create_gist("Answer this to cross the bridge", files)
comments = [c for c in gist.iter_comments()]
# []
comment = gist.create_comment("Bogus. This will not work.")
# Which of course it didn't, because you're not logged in
# comment == None
print(gist.html_url)


# works also in blocks eg from
# https://gist.github.com/anonymous/b839e3a4d596b215296f
# to
# http://bl.ocks.org/anonymous/b839e3a4d596b215296f
Beispiel #9
0
 def test_create_gist(self):
     """Show that github3.create_gist proxies to GitHub."""
     args = ("description", {"files": ["file"]})
     github3.create_gist(*args)
     self.gh.create_gist.assert_called_once_with(*args)
Beispiel #10
0
# https://github3py.readthedocs.org/en/master/examples/gist.html#creating-an-anonymous-gist

# >sudo pip install github3.py

from __future__ import print_function

from github3 import create_gist

files = {
    'spam.txt' : {
        'content': 'What... is the air-speed velocity of an unladen swallow?'
        }
    }
try:
    gist = create_gist('Answer this to cross the bridge', files)
    comments = [c for c in gist.iter_comments()]
    # []

    comment = gist.create_comment('Bogus. This will not work.')

# Which of course it didn't, because you're not logged in
# comment == None
    print(gist.html_url)


# works also in blocks eg from
# https://gist.github.com/anonymous/b839e3a4d596b215296f
# to
# http://bl.ocks.org/anonymous/b839e3a4d596b215296f