-2

I'd like to get this curl command to run in a Python Script

curl -H "public-api-token: 049cxxxxxc026ef7364fa38c8792" -X PUT -d "urlToShorten=google.com" https://api.shorte.st/v1/data/url

but I have now clue how.

Gutz-Pilz
  • 319
  • 6
  • 16
  • 2
    Have you tried anything? Do you need to capture the output from that command. Have you looked at any python documentation about running commands? – Etan Reisner Jun 23 '15 at 16:43
  • docs is always a good start http://pycurl.sourceforge.net/doc/quickstart.html – pmod Jun 23 '15 at 19:11

1 Answers1

1
def make_tiny(url):
    connection = httplib.HTTPSConnection('api.shorte.st', 443)
    connection.connect()
    connection.request('PUT', '/v1/data/url', json.dumps({
           "urlToShorten": url,
         }), {
           "public-api-token": "049cd75ad7axxx26ef7364fa38c8792",
           "Content-Type": "application/json"
         })
    results = json.loads(connection.getresponse().read())
    return results.get("shortenedUrl", "none").decode('utf-8')

Thanks anyway!

Gutz-Pilz
  • 319
  • 6
  • 16