OSDN Git Service

implement PV and author listing
authorhylom <hylom@mbwhite.local>
Wed, 28 Apr 2010 10:38:50 +0000 (19:38 +0900)
committerhylom <hylom@mbwhite.local>
Wed, 28 Apr 2010 10:38:50 +0000 (19:38 +0900)
fetch_storylist.py
stat2.py
template/root.html

index bdbabcd..62027e4 100755 (executable)
@@ -129,13 +129,14 @@ def insert_story_info(otp, story_info):
     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))
index 330d93d..b529244 100755 (executable)
--- a/stat2.py
+++ b/stat2.py
@@ -13,6 +13,9 @@ import sqlite3
 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)
@@ -26,13 +29,25 @@ class StatApp(BigBlack):
                                            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())
@@ -49,13 +64,21 @@ class StatApp(BigBlack):
             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 = []
@@ -66,10 +89,21 @@ class StatApp(BigBlack):
             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
index 1e2950d..a8a06b5 100644 (file)
 <div id="result_header">topic1:${topic1} topic2:${topic2}</div>
 <div id="list">
 <table border="1" cellpadding="4" cellspacing="0">
-    <tr><th>#</th><th>date</th><th>time</th><th>title</th></tr>
+    <tr>
+      <th>#</th>
+      <th>date</th>
+      <th>time</th>
+      <th>author</th>
+      <th>title</th>
+      <th>PV</th>
+    </tr>
 
     % for item in result:
     <tr>
       <td>${str(item["index"])}</td>
       <td>${item["date"]}</td>
       <td>${item["time"]}</td>
+      <td>${item["author"]}</td>
       <td><a href="${item['url']}">${item["title"]}</a></td>
+      <td>${item["pageviews"]}</td>
     </tr>
     % endfor