1

I have the following code which submits links to Tinyurl:

for u in tinyurl.create('http://audiotechracy.blogspot.co.uk/2014/03/reviewing-synapse-antidote-rack.html',
                        'http://audiotechracy.blogspot.co.uk/2014/03/free-guitar-patches-for-propellerhead.html',
                        'http://audiotechracy.blogspot.co.uk/2014/02/get-free-propellerhead-rock-and-metal.html',
                        'http://audiotechracy.blogspot.co.uk/2014/02/in-spotlight-in-this-rack-extension.html',

However everytime I submit the link I always get the same shortened link. I did not realise this would be the case at first but it is apparently because Tinyurl uses an algorithm to shorten long links, thus causing the short link to be the same every time. On the Tinyurl site itself though there is an option to add a custom alias which will get around the problem, however I cannot find any syntax that shows how to do this via the Python Tinyurl module.

Does anyone know the syntax/have an alternative method they could suggest?

Thanks

gdogg371
  • 3,879
  • 14
  • 63
  • 107
  • You mean you want to create a custom *alias*? There is no custom domain option. – Martijn Pieters Apr 07 '14 at 17:47
  • @MartijnPieters yes sorry, that...will edit post now. – gdogg371 Apr 07 '14 at 17:48
  • And the API will create new shortened URLs for each URL you pass in; I suspect you are doing something else wrong. – Martijn Pieters Apr 07 '14 at 17:51
  • @MartijnPieters i thought if you fed it the same long link every time it would always generate the same short link? is that not the case? is there an option for adding a custom alias via Python? – gdogg371 Apr 07 '14 at 17:54
  • Right, yes, it'll re-use existing TinyURL aliases for URLs if one has already been created. Their API does *not* offer any options to pick your own alias, and I suspect that they'll not let you create custom aliases for already shortened links either. – Martijn Pieters Apr 07 '14 at 17:55
  • @MartijnPieters i've just been to the site and submitted a link i've already submitted and just made up a random number. The site then produced a shortened URL made up of just that number: 'http://tinyurl.com/94839483493849384'...there must be a way to code that if you can do it manually? – gdogg371 Apr 07 '14 at 17:58
  • The `/api-create.php` API method doesn't support an `alias` option, in any case. You'll have to ask TinyURL.com, they don't appear to publish an API. – Martijn Pieters Apr 07 '14 at 17:59
  • FWIW, the Python library you are using is exceedingly simple and certainly doesn't support picking the alias to use. – Martijn Pieters Apr 07 '14 at 18:01
  • @martijnpieters are there any other alternative methods via python to generate custom shortened urls that are different each time? the custom bit is not essential, but them being different is. – gdogg371 Apr 07 '14 at 18:01
  • Nope, I know of none. sorry. – Martijn Pieters Apr 07 '14 at 18:06
  • Are you firm on sticking with tinyurl.com? Other providers may offer more complete solutions. – ghoti Apr 07 '14 at 18:11
  • @ghoti no it doesnt need to be them but i havent found any syntax so far to do it via anyone... – gdogg371 Apr 07 '14 at 18:17

1 Answers1

1

this can be done via sending parameters in the get request as follows:

    import requests

    site = 'long url'
    name = 'short name'
    data = {'url': site,
            'submit': 'Make TinyURL!',
            'alias': name}
    r = requests.get('https://www*tinyurl*com/create*php?',params=data)
                    #replace * with . SO blocks the URL.

sorry for the bad formatting, first post on SO. Have fun!

galsolom
  • 56
  • 3
  • Well, if you already know the formatting is bad, why don't you try to improve it? [Here](https://meta.stackexchange.com/help/formatting) is a page listing the most important formatting options – Neuron Apr 26 '18 at 22:42