然后我可以在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
对于MySQL,请参阅以下问题:Python MySQL module
还有一个^{cd1>}模块,您可以在平面sqlite文件上使用,如:
相关问题 更多 >
编程相关推荐