python - Shortened URLs need randomising -


i have following code working correctly. 3 urls shortened put content of 3 different tweets submitted twitter. each time url shortened shortened url same. because of tweets keep being caught twitter spam filter.

is there way randomise appearance of shortened urls stop happening, either using import tinyurl or other method entirely?

import simplejson import httplib2 import twitter import tinyurl  print("python attempt submit tweets twitter...")  try:      api = twitter.api(consumer_key='',                       consumer_secret='',                       access_token_key='',                       access_token_secret='')      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',                         ):         print u         linkvar1 = u         linkvar2 = u         linkvar3 = u      status = api.postupdate("the new synapse antidote rack extension:" + linkvar1 + " #propellerhead #synapse")     status = api.postupdate("free propellerhead guitar patches everyone!" + linkvar2 + " #propellerhead #reason #guitar")     status = api.postupdate("free metal , rock drum samples!" + linkvar3 + " #propellerhead #reason)       print("tweets submitted successfully!")  except exception,e:     print str(e)         print("twitter submissions have failed!!!") 

thanks

when loop through result of tinyurl.create, you're assigning 3 linkvar variables each time, when loop has ended 3 equal last value of u.

if going process same number of urls, can assign them explicitly variables:

linkvar1, linkvar2, linkvar3 = 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', ) 

if number of urls may change, you're better off using list , indexing result want:

linkvars = 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', ) status = api.postupdate("the new synapse antidote rack extension:" + linkvars[0] + " #propellerhead #synapse") status = api.postupdate("free propellerhead guitar patches everyone!" + linkvars[1] + " #propellerhead #reason #guitar") ... 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -