|
Davy Mitchell's Meandering Weblog Home - Angus - Christian - Energy - Fun - General - Internet - IronPython - MoodNews - NintendoDS - Personal - Photos - Podcast - Politics - Python - Scotland - Software Blog Statistics Tag Cloud RSS More Feeds Archives2007-04-212007-04-07 2007-03-24 2007-03-17 2007-03-10 2007-03-03 2007-02-24 2007-02-17 2007-02-10 2007-02-03 |
Snaps From The New Phone Permalink Snaps From The New Phone
Posted by Davy Mitchell on
2007-04-28 14:08:18. Comp.Lang.Python River 2 Permalink First code post in while! Just published an update to Comp.Lang.Python River - hopefully the threading is much better import os
import sys from kirbybase import KirbyBase, KBError from time import time, gmtime, strftime from ftplib import FTP from nntplib import * #Create The Database db = KirbyBase() if os.path.exists('rivnews.tbl'): db.drop('rivnews.tbl') db.create('rivnews.tbl', ['Headline:str','Summary:str', 'ID:int']) #Contact Usenet. s = NNTP('news.blueyonder.co.uk') resp, count, first, last, name = s.group('comp.lang.python') print 'Group', name, 'has', count, 'articles, range', first, 'to', last #Prepare speech output. output = "" riverout = """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=WINDOWS-1250"> <title> Latedecember.co.uk - Comp.Lang.Python River </title> <link rel="stylesheet" href="pc.css" type="text/css" /> </head> <body>""" riverout = riverout + "<h1>Comp.Lang.Python River</h1>" #Fetch Articles. resp, subs = s.xhdr('subject', first + '-' + last) for id, sub in subs[-120:]: output="" for line in s.body(id)[3]: if len(line)>0 and line[0]!='>' and line.find('\t')<0 : if len(line)<3: break if len(line)<8 and line[0]=='-' and line[1]=='-': break if line.find(', 0x')>0 or line.find('wrote:')>0 or line.find('writes:')>0 or line.find(' ')>0: line='' if len(line)>3: if line[0]==' ' and line[1]==' ' and line[2]==' ' and line[3]==' ' : line='' if len(line)>0: output = output + line if output.find('Hatred FAQ')>0 or output.find('****************')>0: output="" if len(output)>10: db.insert('rivnews.tbl', {'Headline': sub.replace('Re: ','') , 'Summary':output, 'ID':int(id)}) #Add Articles to DB. results = db.select('rivnews.tbl', ['recno'], ['*'], sortFields=['Headline','ID'], returnType='dict') #Create long string with speech data and articles. previousHL = "" article = 0 for rec in results: article = article + 1 if rec['Headline']!=previousHL: riverout = riverout + "<h2>" + rec['Headline'] + "</h2>" previousHL = rec['Headline'] if (article % 2) == 1: riverout = riverout + "<p style=""background:#cccccc;"">" + rec['Summary'] + "</p>" else: riverout = riverout + "<p style=""background:#eeeeee;"">" + rec['Summary'] + "</p>" riverout = riverout + """<hr/><a href=""needgod.com"">needgod.com</a></body></html>""" file = open("river.html", 'w') file.write(riverout) file.close()
Posted by Davy Mitchell on
2007-04-28 13:58:36. |
|