a
    Dh
                     @   sj   d dl mZmZ d dlmZ d dlmZmZmZ e Z	ee	Z
e ZeddZededdd	Zd
S )    )	APIRouterRequest)Jinja2Templates)
open_mysqlget_mysql_credsget_pingconf_vars	templates)	directoryz/readarticle)requestc           	         sB  | j d}d }g }d }ztt}|jdd}|d|f |  |d|f | }|rdD ]&}t||t	rf|| 
d||< qf|d|f | }|D ]B}d	D ]8}||}t|t	r|
d||< q|d u rd
||< qqW d    n1 s0    Y  W |r.|  n|r,|  0 td| ||dS )NArtNumT)
dictionaryz
                UPDATE Articles
                SET ViewCnt = IFNULL(ViewCnt, 0) + 1
                WHERE ArtNum = %s
            aU  
                SELECT a.ArtNum, a.Title, a.Source, a.URL AS URL_Source, 
                       a.PubDate, a.Author, a.PostDate, a.ViewCnt, a.Article,
                       c.CatName
                FROM Articles a
                JOIN Categories c ON a.CatNum = c.CatNum
                WHERE a.ArtNum = %s AND a.Deleted = 0
            )TitleZSourceZ
URL_SourceZAuthorZArticleZCatNameZViewCntzutf-8a  
                SELECT c.ComNum, c.ArtNum, i.Name AS HandleStr,
                       c.ReplyToComNum, c.ReplyToHandleStr,
                       c.Comment, c.PostDate
                FROM Comments c
                JOIN Handles h ON c.HandleID = h.HandleID
                JOIN ID i ON h.HandleID = i.IDNum
                WHERE c.ArtNum = %s and c.ComNum > 0
                ORDER BY c.ComNum
            )Z	HandleStrZReplyToHandleStrComment zreadarticle.html)r
   articlecomments)query_paramsgetr   mysql_credscursorexecutecommitfetchone
isinstancebytesdecodefetchallcloser   TemplateResponse)	r
   art_numr   r   r   connkeycvalue r$   ./wd/v2025.freedom4um.com/routes/readarticle.pyread_article   sR    
	


.

r&   N)fastapir   r   fastapi.templatingr   utils.pingdatar   r   r   PingConfr   routerr   r   r&   r$   r$   r$   r%   <module>   s   
