Browse Source

comment has titles

boyska 3 years ago
parent
commit
49fb82971b
4 changed files with 14 additions and 8 deletions
  1. 4 3
      app.py
  2. 4 3
      parse_comment.php
  3. 5 2
      templates/base.html
  4. 1 0
      templates/news.html

+ 4 - 3
app.py

@@ -2,12 +2,13 @@ import os
 from datetime import datetime
 
 from flask import Flask, redirect, render_template, request, url_for
-from flask_paginate import Pagination
-from flask_sqlalchemy import SQLAlchemy
 # from sqlalchemy import Column, Integer, String
 # from sqlalchemy.ext.declarative import declarative_base
 from sqlalchemy.orm import relationship
 
+from flask_paginate import Pagination
+from flask_sqlalchemy import SQLAlchemy
+
 app = Flask(__name__)
 app.config["SQLALCHEMY_DATABASE_URI"] = os.getenv(
     "DB_URI", "sqlite:///news.db"
@@ -56,7 +57,7 @@ class Comments(db.Model):
     nid = db.Column(db.ForeignKey("news.nid"))
     num = db.Column(db.Integer)
     author = db.Column(db.Unicode)
-    # title = db.Column(db.Unicode)
+    title = db.Column(db.Unicode)
     body = db.Column(db.Unicode)
     published = db.Column(db.String)
     # display = db.Column(db.Unicode)

+ 4 - 3
parse_comment.php

@@ -81,6 +81,7 @@ function extract_comments_from_html(string $html): array {
         );
         $meta['text'] = pup_selector($comment, 'tr:nth-child(3) td.testoFTR text{}');
         $meta['html'] = pup_selector($comment, 'tr:nth-child(3) td.testoFTR');
+        $meta['title'] = pup_selector($comment, 'tr:first-child td.titoloFTR:nth-child(2) text{}');
 
         if($date !== false) {
             $meta['published'] = strftime('%s', $date);
@@ -161,7 +162,7 @@ function save($db, $metadata) {
     foreach($metadata['comments'] as $comm)
     {
         $i++;
-        $stm = $db->prepare('INSERT OR REPLACE INTO comments(nid, num, published, author, body) VALUES (?,?,?,?,?)');
+        $stm = $db->prepare('INSERT OR REPLACE INTO comments(nid, num, published, author, title, body) VALUES (?,?,?,?,?,?)');
         if($stm === false) {
             print("error during INSERT:   ");
             print($db->errorInfo()[2]);
@@ -170,9 +171,9 @@ function save($db, $metadata) {
         $stm->bindParam(1, $metadata['nid']);
         $stm->bindParam(2, $i);
         $stm->bindParam(3, $comm['published']);
-        //$stm->bindParam(3, $comm['title']);
         $stm->bindParam(4, $comm['author']);
-        $stm->bindParam(5, $comm['html']);
+        $stm->bindParam(5, $comm['title']);
+        $stm->bindParam(6, $comm['html']);
         $stm->execute();
     }
 }

+ 5 - 2
templates/base.html

@@ -9,11 +9,14 @@
     margin: 1em;
     border: 1px solid blue;
 }
+header {
+    background-color: #003366;
+    color: white;
+}
+h3 { margin: 0 0 0 1em; }
 header .meta {
     text-align: right;
     font-style: italic;
-    background-color: #003366;
-    color: white;
     padding: 0.5em 1em;
     font-family: sans-serif;
 }

+ 1 - 0
templates/news.html

@@ -16,6 +16,7 @@
         {% for comm in comments %}
         <div class="article-comment">
             <header>
+                <h3>{{comm.title}}</h3>
                 <div class="meta">
                     <div class="author">{{comm.author}}</div>
                     <div class="published"><time>{{comm.published_datetime.strftime("%d %b %Y - %H:%M")}}</time></div>