-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.mu
executable file
·78 lines (70 loc) · 3.32 KB
/
list.mu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
# nomadForum - a forum on the NomadNetwork
# Copyright (C) 2023-2024 AutumnSpark1226
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import os
import math
import main
debug = False
if "DEBUG" in os.environ:
if os.environ["DEBUG"].lower() == "true":
debug = True
import traceback
try:
link_id, remote_identity = main.handle_ids()
main.print_header(link_id)
page = 0
sort = "active"
for env_variable in os.environ:
if env_variable == "var_page":
page = int(os.environ[env_variable])
elif env_variable == "var_sort":
sort = os.environ[env_variable]
if sort == "new":
order_sql_statement = "created DESC"
elif sort == "old":
order_sql_statement = "created ASC"
elif sort == "title_asc":
order_sql_statement = "title COLLATE NOCASE ASC"
elif sort == "title_desc":
order_sql_statement = "title COLLATE NOCASE DESC"
else:
order_sql_statement = "last_action DESC"
print()
print(f"Sort: `Ff22`_`[Active`:{main.page_path}/list.mu`sort=active]`_`f `Ff22`_`[New`:{main.page_path}/list.mu`sort=new]`_`f `Ff22`_`[Old`:{main.page_path}/list.mu`sort=old]`_`f `Ff22`_`[Title`:{main.page_path}/list.mu`sort=title_asc]`_`f `Ff22`_`[Title (reverse)`:{main.page_path}/list.mu`sort=title_desc]`_`f")
print()
posts = main.query_database(f"SELECT post_id, username, title, datetime(created, 'unixepoch') FROM posts ORDER BY {order_sql_statement}")
posts_cut_to_page = posts[page * 25:(page + 1) * 25]
for post_data in posts_cut_to_page:
post_title = post_data[2].replace("\\`", "\'") # "`" breaks the link
# "]" breaks the link
post_title = post_title.replace("[", "(")
post_title = post_title.replace("]", ")")
print("-")
if post_data[1] != "[DELETED]":
display_name = main.query_database(f"SELECT display_name FROM users WHERE username = '{post_data[1]}'")[0][0]
username_styled = f"`Ff22`_`[{main.remove_micron(display_name)}`:{main.page_path}/profile.mu`username={post_data[1]}]`f`_"
else:
username_styled = "`Ff22[DELETED]`f"
print(f"{username_styled}: `Ff22`_`[{post_title}`:{main.page_path}/view.mu`post_id={post_data[0]}]`_`f ({post_data[3]} (UTC))")
print("-")
max_page_count = math.floor((len(posts) - 1) / 25)
print(f"`Ff22`_`[<< Previous page`:{main.page_path}/list.mu`sort={sort}|page={str(max(0, page - 1))}]`_`f Page {str(page + 1)} of {max_page_count + 1} `Ff22`_`[Next page >>`:{main.page_path}/list.mu`sort={sort}|page={str(min(max_page_count, page + 1))}]`_`f")
main.close_database()
except:
print("An error occured")
if debug:
traceback.print_exc()
exit(10)