Skip to content

Instantly share code, notes, and snippets.

@proxypoke proxypoke/git.io.py
Created Feb 10, 2013

Embed
What would you like to do?
#!/usr/bin/env python3
# git.io - generate git.io URLs
#
# Author: slowpoke <mail+git@slowpoke.io>
#
# This program is free software under the non-terms
# of the Anti-License. Do whatever the fuck you want.
# See http://anti-licen.se for a copy.
#
# Github: https://www.github.com/proxypoke/kirschwasser
import argparse
# pip install sh - you won't regret it.
import sh
parser = argparse.ArgumentParser(description="Generate git.io URLS.")
parser.add_argument("url", help="the url to shorten", type=str)
parser.add_argument("-n", "--name", help="the (optional) name to use", type=str)
args = parser.parse_args()
command = '-i http://git.io -F url={0}'.format(args.url)
if args.name:
command += ' -F code={0}'.format(args.name)
result = sh.curl(command.split())
result.split('\n')
for r in result:
if r.startswith('Location'):
r = r.split(': ')[-1]
print(r.strip())
exit(0)
print("Something went wront. Here's the full curl output:")
print("==================================================")
print(result)
print("==================================================")
exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.