#!/usr/bin/python
import re
links = []
inFile = open("delicious.html")
inText = inFile.read()
inFile.close()
# break the page up into individual entries and iterate over each of these
divstring = re.compile('
..
.*?
.
', re.S)
iterator = divstring.finditer(inText)
for match in iterator:
# pull out the resource url
urlstring = re.compile('')
if urlstring.search(match.group()):
url = urlstring.search(match.group()).group(1)
# pull out the link text
linktextstring = re.compile('(.*?)')
if linktextstring.search(match.group()):
linktext = linktextstring.search(match.group()).group(1)
# pull out the number of other people who linked here; default to 0
numstring = re.compile('>and (\d*?) other people<')
num = 0
if numstring.search(match.group()):
num = int(numstring.search(match.group()).group(1))
# if everything is here, add this entry to the links list
if url and linktext and num:
links.append((num, url, linktext))
# remove duplicates
cleanlinks = []
for y in links:
if y not in cleanlinks:
cleanlinks.append(y)
# sort and then reverse for largest comes first ordering
cleanlinks.sort()
cleanlinks.reverse()
# make an html page containing pages more than 30 people are linking to
htmlpage = '''
tasty!
One of the main purposes of social bookmarking systems is allowing people to see what
other people are bookmarking. I frequently find things that people are linking
to very interesting, and thought it would be nice to slap together a system that could
tell me, automatically, what lots of other people have just bookmarked at any point in
time. Thus, tasty was born. Tasty is kind of a del.icio.us
mini-zeitgeist. In the spirit of facilitating self-organization, tasty is a kind of pheromone
trail allowing me and others to find the resources other members of the hive found useful,
interesting, humorous, or for some other reason worth visiting again.
tasty! is updated every 15 minutes, and is also available as
.
And now, the links (number indicates how many del.icio.us users are linking here):
'''
for x in cleanlinks:
if x[0] > 30:
htmlpage = htmlpage + '
\ntasty! is written in Python. If you improve the '
htmlpage = htmlpage + 'source please let me know at david.wiley-at-usu.edu.\n\n'
g = open('/path/to/index.html', 'w')
g.write(htmlpage)
g.close
# make an RSS version
rsspage = '''tasty!
http://opencontent.org/tasty/
shows the most popular sites recently bookmarked by del.icio.us users
en-us60
'''
for x in cleanlinks:
if x[0] > 30:
rsspage = rsspage + '\n('+str(x[0])+') '+x[2]+'\n'+x[1]+'\nbookmarked by '+str(x[0])+' people\n\n'
rsspage = rsspage + '\n'
b = open('/path/to/tasty.rss', 'w')
b.write(rsspage)
b.close