results=cursor.execute("select nick, time from urlhistory where url=? and chan=?",(url,channel)).fetchall()
j=0
now=datetime.now()
nicks=[]
foriinxrange(len(results)):
reltime=datetime.fromtimestamp(results[j][1])
if(now-reltime)>expiration_period:
conn.execute("delete from urlhistory where url=? and chan=? and nick=? and time=?",(url,channel,results[j][0],results[j][1]))
results.remove(results[j])
else:
nicks.append(results[j][0])
j+=1
returnnicks
defget_nicklist(nicks):
nicks=list(set(nicks))
nicks.sort()
l=len(nicks)
ifl==0:
return""
elifl==1:
returnnicks[0]
elifl==2:
returnnicks[0]+" and "+nicks[1]
else:
result=""
foriinxrange(l-1):
result+=nicks[i]+", "
result+="and "+nicks[-1]
returnresult
defdbconnect(db):
"check to see that our db has the the seen table and return a connection."
conn=sqlite3.connect(db)
results=conn.execute("select count(*) from sqlite_master where name=?",
("urlhistory",)).fetchone()
if(results[0]==0):
conn.execute("create table if not exists urlhistory(url text not null, nick text not null, chan text not null, time datetime not null, primary key(url, nick, chan, time));")