Created
February 10, 2013 00:11
-
-
Save proxypoke/4747683 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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