0

I am trying to code a website similar to reddit where people can post stories and then vote on them

So right now, I have some Python code to create a time score (PostDate) and a general rating score (VoteStatus), however I need to know how to reference/manipulate fields in an SQL table with Python.

Any help?

    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                
2
  • What do you mean by reference/manipulate? Do you mean update existing records? Commented May 8, 2011 at 15:18
  • So when a user submits a story, their post is timestamped automatically in a field in the SQL table. I want my python code to reference that timestamp in PostDate to create a score in VoteStatus. The value VoteStatus will be calculated for each post and then be inputted as a value in the table for each post - which a new table will then be sorted by. Commented May 8, 2011 at 15:35

1 Answer 1

0

For MySQL, see this question: Python MySQL module

There is also an sqlite3 module that you can use on a flat sqlite file, like so:

import sqlite3
conn = sqlite3.connect('mydb.db')
rows = list(conn.execute("SELECT * FROM Database ORDER BY VoteStatus"))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.