print "Tweet to HTML Converter\n" # print "(C)2013. Distributed under the GNU General Public License compliments of P. K. Carlisle LLC " print "at www.pkcarlisle.com. Notes to mail@pkcarlisle.com. Follow on Twitter @pkcarlislellc." # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # This prints simple usage instructions print "\n\nThis program needs two pieces of input...\n\n" print "1) Tweet text. Example: @phil check out this #new #app\n" print "2) A web address. Example: http://www.pkcarlisle.com/tweet2html.py \n\n" print "This program creates two pieces of output...\n\n" print "3) A single block of HTML code suitable for adding to a webpage as a link to an image:" print " Example: http://twitter.com/share?text=%40phil%20check%20out%20this%20%23new%20%23app&url=http://www.pkcarlisle.com/tweet2html.py \n" print "4) AND extended HTML for inserting directly into HTML code:" print " Example: Share on Twitter\n\n" # Get the TEXT portion of the Tweet here... original = raw_input("Enter text of the Tweet... ") if len(original) == 0: print "Invalid (blank) tweet text entered!" exit(1) else: stringread = len(original) charcounter = 0 tweettext = 'http://twitter.com/share?text=' while charcounter < stringread: if original[charcounter] == '@': tweettext = tweettext + '%40' charcounter = charcounter + 1 elif original[charcounter] == '#': tweettext = tweettext + '%23' charcounter = charcounter + 1 elif original[charcounter] == ' ': tweettext = tweettext + '%20' charcounter = charcounter + 1 else: tweettext = tweettext + original[charcounter] charcounter = charcounter + 1 # #The user text has been parsed, now start the URL portion... tweettext = tweettext + '&url' # Get the URL portion of the HTML here... siteurl = raw_input("Type or COPY\\PASTE a URL... ") if len(siteurl) == 0: print "Invalid (blank) URL entered!" exit(1) else: stringread = len(siteurl) charcounter = 0 #variable convsiteurl is a converted/reformatted variable siteurl #variable convsiteurl declared containing first char of site name convsiteurl = '=' while charcounter < stringread: if siteurl[charcounter] == '@': convsiteurl = convsiteurl + '%40' charcounter = charcounter + 1 elif siteurl[charcounter] == '#': convsiteurl = convsiteurl + '%23' charcounter = charcounter + 1 elif siteurl[charcounter] == ' ': convsiteurl = convsiteurl + '%20' charcounter = charcounter + 1 else: convsiteurl = convsiteurl + siteurl[charcounter] charcounter = charcounter + 1 #use now cleaned and converted strings for final output tweettext = tweettext + convsiteurl # make a simplified Twitter link # make a complete HTML statement and embed the Twitter link exturl = 'Share on Twitter' #print it prettily print "\nThe direct Twitter Compatible Link is:" print tweettext print "\n\nThe extended HTML code is:" print exturl print "\n"