User:OZ/ass2
palindrome
import feedparser
RSS = feedparser.parse(input("Type your RSS with quotes: "))
#RSS = feedparser.parse("http://feeds.feedburner.com/wooster")
for feed in RSS.entries:
print(" ".join (feed.title.split()[:-1] + feed.title.split()[::-1]))
webcomics
import urllib2, urlparse, html5lib
def absolutizeURL (href, base):
if not href.lower().startswith("http://"):
return urlparse.urljoin(base, href)
return href
def openURL (url):
"""
returns (page, actualurl)
sets user_agent and resolves possible redirection
realurl maybe different than url in the case of a redirect
"""
request = urllib2.Request(url)
user_agent = "Mozilla/5.0 (X11; U; Linux x86_64; fr; rv:1.9.1.5) Gecko/20091109 Ubuntu/9.10 (karmic) Firefox/3.5.5"
request.add_header("User-Agent", user_agent)
pagefile=urllib2.urlopen(request)
realurl = pagefile.geturl()
return (pagefile, realurl)
parser = html5lib.HTMLParser(tree=html5lib.treebuilders.getTreeBuilder("dom"))
(f,url1)=openURL("http://www.woostercollective.com")
tree1 = parser.parse(f)
f.close()
tree1.normalize()
tags1 = tree1.getElementsByTagName("img")
# print tags
(f,url2)=openURL("http://www.stencilrevolution.com/photopost/")
tree2 = parser.parse(f)
f.close()
tree2.normalize()
tags2 = tree2.getElementsByTagName("img")
# print tags
print """<html><body>"""
import random
random.shuffle(tags1)
for (tag1, tag2) in zip (tags1, tags2):
# print the original tag with all the attributes it originally had
var=tag1.getAttribute("src")
var=absolutizeURL(var,url1)
print "<img src='" + var + "' height='200' width='200' />"
# print the original tag with all the attributes it originally had
var=tag2.getAttribute("src")
var=absolutizeURL(var,url2)
print "<img src='" + var + "' height='200' width='200' />"
print """</html></body>"""