radames commited on
Commit
7326e06
1 Parent(s): 838a51d

define my own power

Browse files
Files changed (2) hide show
  1. app.py +1 -1
  2. db.py +4 -0
app.py CHANGED
@@ -214,7 +214,7 @@ class Sort(str, Enum):
214
  def get_page(page: int = 1, sort: Sort = Sort.trending):
215
  page = page if page > 0 else 1
216
  if sort == Sort.trending:
217
- sort_query = "json_extract(data, '$.likes') / POW((JULIANDAY('now') - JULIANDAY(datetime(json_extract(data, '$.lastModified')))) + 2, 2) DESC"
218
  elif sort == Sort.recent:
219
  sort_query = "datetime(json_extract(data, '$.lastModified')) DESC"
220
  elif sort == Sort.likes:
 
214
  def get_page(page: int = 1, sort: Sort = Sort.trending):
215
  page = page if page > 0 else 1
216
  if sort == Sort.trending:
217
+ sort_query = "json_extract(data, '$.likes') / MYPOWER((JULIANDAY('now') - JULIANDAY(datetime(json_extract(data, '$.lastModified')))) + 2, 2) DESC"
218
  elif sort == Sort.recent:
219
  sort_query = "datetime(json_extract(data, '$.lastModified')) DESC"
220
  elif sort == Sort.likes:
db.py CHANGED
@@ -1,6 +1,9 @@
1
  import sqlite3
2
  from pathlib import Path
 
3
 
 
 
4
 
5
 
6
 
@@ -21,6 +24,7 @@ class Database:
21
 
22
  def get_db(self):
23
  db = sqlite3.connect(self.db_file, check_same_thread=False)
 
24
  db.row_factory = sqlite3.Row
25
  return db
26
 
 
1
  import sqlite3
2
  from pathlib import Path
3
+ import math
4
 
5
+ def power(x, y):
6
+ return math.pow(x, y)
7
 
8
 
9
 
 
24
 
25
  def get_db(self):
26
  db = sqlite3.connect(self.db_file, check_same_thread=False)
27
+ db.create_function("MYPOWER", 2, power)
28
  db.row_factory = sqlite3.Row
29
  return db
30