Added support for view exports
This commit is contained in:
parent
403ac07661
commit
aeb6b1a635
BIN
dist/drstats-1.3.37-py3-none-any.whl
vendored
BIN
dist/drstats-1.3.37-py3-none-any.whl
vendored
Binary file not shown.
BIN
dist/drstats-1.3.37.tar.gz
vendored
BIN
dist/drstats-1.3.37.tar.gz
vendored
Binary file not shown.
BIN
drstats.db
BIN
drstats.db
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Before Width: | Height: | Size: 1.9 MiB After Width: | Height: | Size: 1.9 MiB |
Binary file not shown.
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 44 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -2,6 +2,7 @@ from drstats import db
|
||||
import functools
|
||||
import sys
|
||||
import pathlib
|
||||
import json
|
||||
|
||||
printr = functools.partial(print, file=sys.stderr)
|
||||
|
||||
@ -35,7 +36,7 @@ def dump():
|
||||
"```",
|
||||
)
|
||||
printr(text)
|
||||
with pathlib.Path("export/rants-" + user + ".txt").open("w") as f:
|
||||
with pathlib.Path("export/rants-" + user + ".txt").open("w+") as f:
|
||||
f.write(user)
|
||||
f.write(" said ")
|
||||
f.write(text)
|
||||
@ -53,7 +54,7 @@ def dump():
|
||||
"```",
|
||||
)
|
||||
printr(text)
|
||||
with pathlib.Path("export/posts-" + user + ".txt").open("w") as f:
|
||||
with pathlib.Path("export/posts-" + user + ".txt").open("w+") as f:
|
||||
f.write(user)
|
||||
f.write(" said ")
|
||||
f.write(text)
|
||||
@ -68,3 +69,8 @@ def dump():
|
||||
printr(line)
|
||||
print(line)
|
||||
print("```")
|
||||
|
||||
for view in db.get_views():
|
||||
print(f"export/view-f{view['name']}.json")
|
||||
with pathlib.Path(f"export/view-f{view['name']}.json").open("w+") as f:
|
||||
json.dump(view, db.query(view['sql']))
|
@ -205,6 +205,9 @@ def get_db():
|
||||
db.query(
|
||||
"CREATE VIEW posts_of_user AS SELECT user_username as username, GROUP_CONCAT(body) as text FROM comments"
|
||||
)
|
||||
db.query("DROP VIEW IF EXISTS contributions_extended_ranked")
|
||||
db.query("CREATE VIEW contributions_extended_ranked AS SELECT ROW_NUMBER() OVER (ORDER BY upvote_ratio DESC) as rank, * FROM contributions_extended ORDER BY upvote_ratio DESC")
|
||||
db.query("CREATE VIEW IF NOT EXISTS views AS SELECT sql, name FROM sqlite_schema WHERE type='view' AND name != 'views';")
|
||||
|
||||
return db
|
||||
|
||||
@ -239,10 +242,14 @@ class Db:
|
||||
self.db = None
|
||||
|
||||
|
||||
def get_views():
|
||||
with Db() as db:
|
||||
return list(db.query("SELECT * FROM views;"))
|
||||
|
||||
def get_contributions():
|
||||
with Db() as db:
|
||||
contributions = db.query(
|
||||
"SELECT ROW_NUMBER() OVER (ORDER BY upvote_ratio DESC) as rank, * FROM contributions_extended ORDER BY upvote_ratio DESC"
|
||||
"SELECT * FROM contributions_extended_ranked"
|
||||
)
|
||||
return list(contributions)
|
||||
|
||||
@ -252,8 +259,15 @@ def get_upvote_average():
|
||||
|
||||
|
||||
def get_users():
|
||||
return list(set([user["username"] for user in get_contributions()]))
|
||||
"""
|
||||
Retrieve a list of distinct usernames from the contributions table.
|
||||
|
||||
Returns:
|
||||
list: A list of usernames in ascending order.
|
||||
"""
|
||||
|
||||
with Db() as db:
|
||||
return [user["username"] for user in db.query("SELECT DISTINCT username FROM contributions ORDER BY username")]
|
||||
|
||||
def get_user_count():
|
||||
return len(get_users())
|
||||
|
Loading…
Reference in New Issue
Block a user