Snaps From The New Phone Permalink

Snaps From The New Phone


       

Posted by Davy Mitchell on 2007-04-28 14:08:18.
Categories: Angus, Photos, Scotland Tags :  
Like this post? Digg it or Del.icio.us it. |



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 Wink Please suggest changes.

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.
Categories: Python, Podcast, IronPython Tags :   
Like this post? Digg it or Del.icio.us it. |




Locations of visitors to this page