Skip to content

Instantly share code, notes, and snippets.

@proxypoke
Created February 10, 2013 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save proxypoke/4747683 to your computer and use it in GitHub Desktop.
Save proxypoke/4747683 to your computer and use it in GitHub Desktop.
#!/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