cur.execute("""delete from topics where sid=?""", (sid,))
for tag in tags:
- tag = tag.decode("utf-8")
+# tag = tag.decode("utf-8")
cur.execute("""insert into topics ( sid, topic )
values ( :sid, :topic )""",
dict(sid=sid, topic=tag))
if title:
- title = title.decode("utf-8").replace("Open Tech Press |", "").strip()
+# title = title.decode("utf-8").replace("Open Tech Press |", "").strip()
+ title = title.strip()
cur.execute("""update stories set title = :title
where sid = :sid""",
dict(sid=sid, title=title))
import re
import sys
+LOG_DB = "analytics_dat"
+WRITERS = (u"松島浩道", u"末岡洋子", u"二瓶亮史", u"大津真", u"林利明", u"Infostand")
+
class StatApp(BigBlack):
def __init__(self):
BigBlack.__init__(self)
topic2=topic2,
op=""))
+ def get_pvs_info(self, sid):
+ con = sqlite3.connect(LOG_DB)
+ cur = con.cursor()
+ param = "/magazine/" + sid + "%"
+ cur.execute("""select * from logdata where url like ?""", (param,))
+ sum = 0
+ for row in cur:
+ sum = sum + row[2]
+ cur.close()
+ con.close()
+ return sum
+
def h_query(self):
topic1 = self.cgi.getfirst("topic1", "")
topic2 = self.cgi.getfirst("topic2", "")
DATABASE = "./story.db"
- range_begin = datetime.datetime(2010, 3, 26)
+ range_begin = datetime.datetime(2010, 2, 26)
range_end = datetime.datetime(2010, 4, 26)
begin_t = time.mktime(range_begin.timetuple())
con = sqlite3.connect(DATABASE)
cur = con.cursor()
cur.execute(cmd, (begin_t, end_t, t1, t2))
- else:
+ elif topic1:
cmd = """select sid, title, date from stories where date >= ? and date < ? and sid in (
select sid from topics where topic == ? ) order by date
"""
con = sqlite3.connect(DATABASE)
cur = con.cursor()
cur.execute(cmd, (begin_t, end_t, t1))
+ else:
+ cmd = """select sid, title, date from stories where date >= ? and date < ? and sid in (
+ select sid from topics) order by date
+ """
+ con = sqlite3.connect(DATABASE)
+ cur = con.cursor()
+ cur.execute(cmd, (begin_t, end_t))
+
index = 1
result = []
dt = datetime.datetime.fromtimestamp(tm)
localdt = dt + datetime.timedelta(hours=9)
+ # get topics
+ cur2 = con.cursor()
+ author = ""
+ cur2.execute("""select topic from topics where sid=?""", (sid,))
+ for row2 in cur2:
+ if row2[0] in WRITERS:
+ author = row2[0]
+
+ pv = self.get_pvs_info(sid)
d = dict(index=index,
date=localdt.strftime("%y-%m-%d"),
time=localdt.strftime("%H:%M:%S"),
url="http://sourceforge.jp/magazine/" + sid,
+ pageviews=pv,
+ author=author,
title=title)
result.append(d)
index += 1