X-Git-Url: https://harishankar.org/repos/?p=biaweb_qt.git;a=blobdiff_plain;f=biaweb_db.py;fp=biaweb_db.py;h=9b7cb10f72d336440b3fd639812710ecf34525e5;hp=b310972f9d8cf70d48976760988d6a512879c1d1;hb=f37ae5235dba470cf02e25a885b83a2bc9c78694;hpb=bfa2d7e7b048794a95590ee79ba41aa861835cfa diff --git a/biaweb_db.py b/biaweb_db.py index b310972..9b7cb10 100644 --- a/biaweb_db.py +++ b/biaweb_db.py @@ -207,6 +207,34 @@ def get_configuration (dbname): except sqlite3.Error: return False +# Function to get the latest articles (inner join with categories to get category stub) +def site_latest_articles (dbname, num_arts): + try: + conn = sqlite3.connect (dbname) + c = conn.cursor () + c.execute ("SELECT * FROM articles INNER JOIN categories ON articles.cid=categories.cid \ + ORDER BY cdate DESC LIMIT ?;", (num_arts,)) + conn.commit () + rows = c.fetchall () + conn.close () + return rows + except sqlite3.Error: + return False + +# Function to get the best rated articles (inner join with categories to get category stub) +def site_get_bestrated (dbname): + try: + conn = sqlite3.connect (dbname) + c = conn.cursor () + c.execute ("SELECT * FROM articles INNER JOIN categories ON articles.cid=categories.cid \ + ORDER BY rating DESC LIMIT 5;") + conn.commit () + rows = c.fetchall () + conn.close () + return rows + except sqlite3.Error: + return False + # Function to get list of articles (either full list or just in a category def get_articles (dbname, category_id=None): try: