在Python代码中引用/操控SQL字段

2024-06-01 04:03:58 发布

您现在位置:Python中文网/ 问答频道 /正文

然后我可以在reddam网站上发布类似的文章

所以现在,我有一些Python代码来创建时间分数(PostDate)和一般评分(VoteStatus),但是我需要知道如何使用Python引用/操作SQL表中的字段。在

有什么帮助吗?在

    import datetime

    def PostDate(PostID):
        dday = datetime.fromtimestamp(#I need a way to reference the timestamp
                     #field of a specifc PostID entry in each of these blank parens).day
        mmonth = datetime.fromtimestamp().month
        yyear = datetime.fromtimestamp().year
        hhour = datetime.fromtimestamp().hour
        mminute = datetime.fromtimestamp().minute
        ssecond = datetime.fromtimestamp().second
        return ((dday * 1000000) + (mmonth * 100000000) + (yyear * 10000000000) + (hhour * 10000) + (mminute * 100) + ssecond)

    def VoteStatus(PostID):
        TimeScore = PostDate(Post)
        cday = datetime.now.day
        cmonth = datetime.now.month
        cyear = datetime.now.year
        chour = datetime.now.hour
        cminute = datetime.now.minute
        csecond = datetime.now.second
        Now = ((cday * 1000000) + (cmonth * 100000000) + (cyear * 10000000000) + (chour * 10000) + (cminute * 100) + csecond)
        timestatus = (Now - TimeScore)
        votes = #Reference the value given in the total votes field in the SQL table
        return (.45 * timestatus) + (.55 * votes)






    SELECT * FROM Database ORDER BY VoteStatus                

Tags: oftheinfieldsqldatetimedefnow