Esempio n. 1
0
    def vimeo_parse(self, id):
        self.id = id
        json = http.get_json("http://vimeo.com/api/v2/video/%s.json" % id)
        title = json[0]["title"]
        thumbnail = json[0]["thumbnail_large"]
        host = "vimeo"
        id = id

        return title, thumbnail, host, id
Esempio n. 2
0
def isgd(url):
    """ shortens a URL with the is.gd PAI """
    url = urlnorm.normalize(url.encode('utf-8'), assume_scheme='http')
    params = urllib.urlencode({'format': 'json', 'url': url})
    request = http.get_json("http://is.gd/create.php?%s" % params)

    if "errorcode" in request:
        raise ShortenError(request["errorcode"], request["errormessage"])
    else:
        return request["shorturl"]
Esempio n. 3
0
def isgd(url):
    """ shortens a URL with the is.gd API """
    url = urlnorm.normalize(url.encode('utf-8'), assume_scheme='http')
    params = urllib.urlencode({'format': 'json', 'url': url})
    request = http.get_json("http://is.gd/create.php?%s" % params)

    if "errorcode" in request:
        raise ShortenError(request["errorcode"], request["errormessage"])
    else:
        return request["shorturl"]
Esempio n. 4
0
    def youtube_parse(self, id):
        self.id = id
        json = http.get_json(
            "http://gdata.youtube.com/feeds/api/videos/%s?v=2&alt=jsonc" % id)
        j = json['data']
        host = "youtube"
        thumbnail = "http://img.youtube.com/vi/%s/2.jpg" % id
        title = j['title']

        return title, thumbnail, host, id
Esempio n. 5
0
def main( argv ):
    """
    Script execution entry point
    @param argv         Arguments passed to the script
    @return             Exit code (0 = success)
    """

    # imports when using this as a script
    import argparse

    # create and configure an argument parser
    parser = argparse.ArgumentParser(
        description = 'List a user\'s GitHub repositories.',
        add_help    = False
    )
    parser.add_argument(
        '-h',
        '--help',
        default = False,
        help    = 'Display this help message and exit.',
        action  = 'help'
    )
    parser.add_argument(
        '-v',
        '--version',
        default = False,
        help    = 'Display script version and exit.',
        action  = 'version',
        version = __version__
    )
    parser.add_argument(
        'user',
        help = 'Specify the GitHub user name.'
    )

    # parse the arguments
    args = parser.parse_args( argv[ 1 : ] )

    # fetch the user's repos
    repos = http.get_json(
        'https://api.github.com/users/%s/repos' % args.user
    )

    # send list of repo names to stdout
    for r in repos:
        print r[ 'name' ]

    # return success
    return 0
Esempio n. 6
0
def main(argv):
    """
    Script execution entry point
    @param argv         Arguments passed to the script
    @return             Exit code (0 = success)
    """

    # imports when using this as a script
    import argparse

    # create and configure an argument parser
    parser = argparse.ArgumentParser(
        description='List a user\'s GitHub repositories.', add_help=False)
    parser.add_argument('-h',
                        '--help',
                        default=False,
                        help='Display this help message and exit.',
                        action='help')
    parser.add_argument('-v',
                        '--version',
                        default=False,
                        help='Display script version and exit.',
                        action='version',
                        version=__version__)
    parser.add_argument('user', help='Specify the GitHub user name.')

    # parse the arguments
    args = parser.parse_args(argv[1:])

    # fetch the user's repos
    repos = http.get_json('https://api.github.com/users/%s/repos' % args.user)

    # send list of repo names to stdout
    for r in repos:
        print r['name']

    # return success
    return 0
Esempio n. 7
0
def haste(text, ext='txt'):
    """ pastes text to a hastebin server """
    data = http.get_json(paste_url + "/documents", post_data=text, get_method='POST')
    return "{}/{}.{}".format(paste_url, data['key'], ext)
Esempio n. 8
0
def googl(url):
    """ shortens a URL with the goo.gl API """
    postdata = urlencode({'api_key': api_key, 'link': url})

    request = http.get_json(short_url, post_data=postdata, get_method='POST')
    return "{}/{}".format(short_url, request['Id'])