-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroutes_dashboard.py
More file actions
302 lines (263 loc) · 9.08 KB
/
routes_dashboard.py
File metadata and controls
302 lines (263 loc) · 9.08 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
import datetime
import os
from litestar import MediaType
from litestar import Response
# from litestar import Request
from litestar import get
# from litestar import post
from litestar.datastructures import Headers
#
# from litestar.exceptions import HTTPException
# from litestar.status_codes import HTTP_403_FORBIDDEN
# from litestar.response import Template
# from functions import (
# get_dhammapada,
# text_to_image,
# ntfy_client,
# box as box_function,
# cowsay as cowsay_function,
# fortune as fortune_function,
# git_pull_repo,
# verify_github_webhook_signature,
# process_github_webhook,
# do_reboot,
# )
from functions import (
get_dhammapada_qid
)
# from aux.params import (
# param_optional_text,
# param_required_text,
# param_padding,
# param_foreground_color,
# param_background_color,
# param_font_size,
# param_box,
# param_cowsay,
# param_fortune,
# param_dhammapada_number,
# param_dhammapada_format,
# )
# from database import Text
# import secret_config
# DEBUG = True
DEBUG = False
noauth = {"exclude_from_auth": True}
# @get("/", include_in_schema=False)
# async def hello_world() -> dict[str, str]:
# """Handler function that returns a greeting dictionary."""
# return {"hello": "world!"}
@get("/dashboard/dhammapada",
include_in_schema=False,
media_type=MediaType.HTML,
summary="dashboard extension that displays the quarter in die dhammapada",
description="From our bot",
**noauth, #pyright: ignore
)
# async def dhammapada_qid_extension(format: param_dhammapada_format = None) -> str:
async def dhammapada_qid_dashboard() -> str | Response:
# qid = quarter in die
text = get_dhammapada_qid(show_time=True, space_padding=True)
# html = (f"<div style=\"width: 100%; text-align: right;\">"
html = (f"<div style=\"width: 100%; text-align: center;\">"
f"<pre style=\"width: 100%;\">"
f"{text}"
f"</pre>"
f"</div>")
# text = f"{current_qid_dhammapada}\n\n{offset}{time}"
# text = f"{current_qid_dhammapada}\n\n{offset}{time}"
# if format == "png":
# png_bytes = text_to_image(text=text,
# padding=22,
# foreground_color="orange",
# background_color="#333366",
# font_size=14
# )
# return Response(
# content=png_bytes,
# media_type="image/png",
# headers=Headers({"Content-Disposition":
# "inline; filename=image.png"})
# )
return Response(
content=html,
media_type="text/html",
headers=Headers({
"Widget-Title": "Buddha saying in the Dhammapada",
"Widget-Title-URL": "https://kassius.org",
"Widget-Content-Frameless": "true",
"Widget-Content-Type": "html",
})
)
return html
# @get("/display-dhammapada",
# media_type=MediaType.TEXT,
# summary="displays dhammapada",
# description="Display a random verse from the Dhammapada if `number` is not specified, verse `number` otherwise",
# **noauth, #pyright: ignore
# )
# async def display_dhammapada(number: param_dhammapada_number = None,
# format: param_dhammapada_format = None,
# padding: param_padding = 22,
# foreground_color: param_foreground_color = "white",
# background_color: param_background_color = "black",
# font_size: param_font_size = 16,
# box: param_box = False
# ) -> str | Response:
#
# dhammapada = get_dhammapada(number=number)
#
# if box:
# text = box_function(text=dhammapada)
# else:
# text = dhammapada
#
# if format == "png":
# png_bytes = text_to_image(text=text,
# padding=padding,
# foreground_color=foreground_color,
# background_color=background_color,
# font_size=font_size
# )
#
# return Response(
# content=png_bytes,
# media_type="image/png",
# headers=Headers({"Content-Disposition":
# "inline; filename=image.png"})
# )
#
# return text
# @get("/text-to-image",
# summary="image from text",
# description="Generates an image from `text`.",
# **noauth, #pyright: ignore
# )
# async def text_to_img(
# text: param_optional_text,
# padding: param_padding = 0,
# foreground_color: param_foreground_color = "white",
# background_color: param_background_color = "black",
# font_size: param_font_size = 16,
# box: param_box = False,
# cowsay: param_cowsay = False,
# fortune: param_fortune = False,
# ) -> Response:
#
# if fortune or not text:
# text = fortune_function()
#
# if cowsay:
# text = cowsay_function(text=text)
#
# if box:
# text = box_function(text=text)
#
# png_bytes = text_to_image(text=text,
# padding=padding,
# foreground_color=foreground_color,
# background_color=background_color,
# font_size=font_size
# )
#
# return Response(
# content=png_bytes,
# media_type="image/png",
# headers=Headers({"Content-Disposition":
# "inline; filename=image.png"})
# )
# @get("/cowsay",
# media_type=MediaType.TEXT,
# summary="cowsay text",
# description="Cowsays `text`",
# **noauth, #pyright: ignore
# )
# async def get_cowsay(text: param_required_text) -> str:
# cowsaying = cowsay_function(text=text)
#
# return cowsaying
# @get("/box",
# media_type=MediaType.TEXT,
# summary="text inside box",
# description="Displays `text` inside box",
# **noauth, #pyright: ignore
# )
# async def get_box(text: param_required_text) -> str:
# text_box = box_function(text=text)
#
# return text_box
# @get("/fortune",
# media_type=MediaType.TEXT,
# summary="displays fortune",
# description="Displays a random fortune",
# **noauth, #pyright: ignore
# )
# async def get_fortune() -> str:
# fortune_text = fortune_function()
#
# return fortune_text
# @get("/specific",
# media_type=MediaType.TEXT,
# summary="displays specific fortune",
# description="Displays a chosen fortune",
# **noauth, #pyright: ignore
# )
# async def get_specific() -> str:
# texts = await Text.select()
# specific_text = "\n\n".join([f"{text['id']}: {text['text']}"
# for text in texts])
return specific_text
# @get("/index",
# media_type=MediaType.HTML,
# summary="template",
# description="Testing templates",
# **noauth, #pyright: ignore
# )
# async def get_index(text: param_required_text) -> Template:
# context = {"text": text}
#
# index = Template(template_name="index.html.jinja2", context=context)
# return index
# @post("/webhook-github",
# include_in_schema=False,
# **noauth, #pyright: ignore
# )
# async def github_webhook_notify(request: Request, data: dict) -> str:
# signature_header = request.headers.getone("X-Hub-Signature-256", "=")
# data_bytes = await request.body()
#
# if verify_github_webhook_signature(data_bytes=data_bytes,
# webhook_secret=secret_config\
# .GITHUB_WEBHOOK_SECRET,
# signature=signature_header):
#
# data_dict = data
# message = process_github_webhook(data=data_dict)
#
# ntfy_client(message=message, title="from /webhook-github",
# priority="default")
#
# git_message = git_pull_repo(data)
# if git_message:
# ntfy_client(message=git_message, title="git pull 'repo'",
# priority="default")
#
# return message
#
# else:
# message = "error checking"
#
# ntfy_client(message=message, title="from /webhook-github",
# priority="high")
#
# raise HTTPException(detail="Invalid signature",
# status_code=HTTP_403_FORBIDDEN)
# @get("/reboot"
# )
# async def reboot() -> str:
# do_reboot()
#
# return ""
# @get("/add_user")
# async def user_add():
# pass