|
|
|
Quelle: http://weblog.mur.at/d2m/
Mit dem Code kann man die Bilder von mks.antville.org in das eigene blog einbinden.
This is the block to insert into your HTML document
<div class=box>
<style type="text/css">
.mks_rss_img img { display: block; border-top: 2px #ccc solid;
margin: 0px; }
#mks_rssimg_0, #mks_rssimg_1, #mks_rssimg_2, #mks_rssimg_3 {}
#mks_rssimg_4, #mks_rssimg_5, #mks_rssimg_6 {display: none;}
</style>
<a href="http://mks.antville.org">
<div><img
src="http://www.antville.org/static/mks/files/mks_logo_small.gif"
border=0 /></div>
<script type="text/javascript"
src="http://weblog.mur.at/~d2m/mks_rss_img.js"></script>
</a>
</div>
- - - 8X - - - - here is how the sidebar is created in code - - -
First i wrote some python code to create the javascript include file in filesystem
# module feedparser from feedparser.org
import feedparser
from xml.dom.minidom import parse, parseString
# file to store the cached data
outfile = '/path/to/public_html/mks_rss_img.js'
def main():
# get the rss feed
f = feedparser.parse('http://mks.antville.org/rss')
# parsing for image data
img = ''
for e in f.entries:
img += e.description
img_p = parseString('<div>' + img + '</div>')
h = img_p.getElementsByTagName('img')
out='document.write(\'<div class="mks_rss_img">'
count=0
# get four images
for hi in h[:4]:
# get the image filename
h_txt = hi.getAttribute('src')
# replacing the original image with the antville thumbnail
h_list = h_txt.split('.')
h_neu = '.'.join(h_list[:-1]) + '_small.jpg'
# add the new imagename to the outstring
out += '<img id="mks_rssimg_' + str(count) + '" src="' + h_neu + '" />'
count += 1
out += '</div>\')'
return out
if __name__ == '__main__':
try:
out = main()
# write to outfile
f = open(outfile,'w')
f.write(out)
f.close()
except:
# do nothing
pass
All thats left is a crontab script to create the javascript include file every so often (i do it every 10 minutes after the hour)
10 * * * * python /path/to/python-module/make_rss_img.py
|
|
• story
220 × gelesen
• keine kommentare.
• meinung sagen
|
neuere
- | home |
ältere |
+
|