|
@@ -7,6 +7,7 @@ import subprocess
|
|
|
import base64
|
|
|
import os
|
|
|
import textwrap
|
|
|
+import sys
|
|
|
|
|
|
base_path = "/messagebase"
|
|
|
|
|
@@ -22,22 +23,89 @@ def format_datetime(value):
|
|
|
|
|
|
# Check Configuring Flask-Caching section for more details
|
|
|
# cache = Cache(app, config={"CACHE_TYPE": "filesystem", "CACHE_DIR": "cache"})
|
|
|
-cache = Cache(app, config={"CACHE_TYPE": "redis", "CACHE_REDIS_HOST": "redis"})
|
|
|
+cache = Cache(
|
|
|
+ app, config={"CACHE_TYPE": "redis", "CACHE_REDIS_HOST": "redis"}
|
|
|
+)
|
|
|
# cache = Cache(app, config={"CACHE_TYPE": "redis", "CACHE_REDIS_HOST": "olympus"})
|
|
|
|
|
|
-import jammin
|
|
|
+# import jammin
|
|
|
+
|
|
|
+import sqlite3
|
|
|
+
|
|
|
+dbconnect = sqlite3.connect("db/message.sqlite3")
|
|
|
+dbc = dbconnect.cursor()
|
|
|
|
|
|
bases = {
|
|
|
- "FSXNET-General": "msgs/fsx_gen",
|
|
|
- "FSXNET-BBS": "msgs/fsx_bbs",
|
|
|
- "FSXNET-BOT": "msgs/fsx_bot",
|
|
|
- "FSXNET-Encryption": "msgs/fsx_cry",
|
|
|
- "FSXNET-Ham Radio": "msgs/fsx_ham",
|
|
|
- "FSXNET-Magicka": "msgs/fsx_mag",
|
|
|
- "FSXNET-Mystic": "msgs/fsx_mys",
|
|
|
+ "FSXNET-General": "fsx_gen",
|
|
|
+ "FSXNET-Ads": "fsx_ads",
|
|
|
+ "FSXNET-BBS": "fsx_bbs",
|
|
|
+ "FSXNET-BOT": "fsx_bot",
|
|
|
+ # "FSXNET-Encryption": "msgs/fsx_cry",
|
|
|
+ "FSXNET-Ham Radio": "fsx_ham",
|
|
|
+ # "FSXNET-Magicka": "msgs/fsx_mag",
|
|
|
+ "FSXNET-Magicka": "fsx_mag",
|
|
|
+ "FSXNET-Mystic": "fsx_mys",
|
|
|
+ "FSXNET-Enigma": "fsx_eng",
|
|
|
# "HappyNet-General": "msgs/hpy_gen",
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+def bbs_get_messages(area):
|
|
|
+ global dbc
|
|
|
+
|
|
|
+ messages = []
|
|
|
+
|
|
|
+ for row in dbc.execute(
|
|
|
+ # "SELECT message_id, to_user_name, from_user_name, subject, modified_timestamp from message WHERE area_tag=?",
|
|
|
+ "SELECT message_id, to_user_name, from_user_name, subject, modified_timestamp from message WHERE area_tag=? ORDER BY message_id;",
|
|
|
+ (area,),
|
|
|
+ ):
|
|
|
+ stamp = pendulum.parse(row[4]).timestamp()
|
|
|
+ messages.append(
|
|
|
+ {
|
|
|
+ "MsgNum": row[0],
|
|
|
+ "number": row[0],
|
|
|
+ "to": row[1],
|
|
|
+ "from": row[2],
|
|
|
+ "subject": row[3],
|
|
|
+ "written": stamp,
|
|
|
+ # // written
|
|
|
+ # // received
|
|
|
+ # // processed
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ return messages
|
|
|
+
|
|
|
+
|
|
|
+def bbs_message(area, msgno):
|
|
|
+ global dbc
|
|
|
+
|
|
|
+ messages = []
|
|
|
+
|
|
|
+ dbc.execute(
|
|
|
+ "SELECT message_id, to_user_name, from_user_name, subject, modified_timestamp, message from message WHERE message_id=?",
|
|
|
+ (msgno,),
|
|
|
+ )
|
|
|
+ row = dbc.fetchone()
|
|
|
+ stamp = pendulum.parse(row[4]).timestamp()
|
|
|
+ return {
|
|
|
+ "MsgNum": row[0],
|
|
|
+ "number": row[0],
|
|
|
+ "to": row[1],
|
|
|
+ "from": row[2],
|
|
|
+ "subject": row[3],
|
|
|
+ "written": stamp,
|
|
|
+ "received": stamp,
|
|
|
+ "processed": stamp,
|
|
|
+ "text": row[5], # .decode("cp437"),
|
|
|
+ "bytes": row[5].encode("cp437")
|
|
|
+ # // written
|
|
|
+ # // received
|
|
|
+ # // processed
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
# bases = {"FSX_BOT": "fsx_bot"}
|
|
|
|
|
|
# @cache.memoize(timeout=5 * 60, key_prefix="messages")
|
|
@@ -45,14 +113,15 @@ bases = {
|
|
|
|
|
|
@cache.memoize(timeout=5 * 60)
|
|
|
def get_messages(base):
|
|
|
- messages = jammin.get_messages(base)
|
|
|
+ messages = bbs_get_messages(base)
|
|
|
messages.reverse()
|
|
|
return messages
|
|
|
|
|
|
|
|
|
@cache.memoize(timeout=60)
|
|
|
def get_message(base, msgno):
|
|
|
- message = jammin.read_message(base, msgno)
|
|
|
+ # message = jammin.read_message(base, msgno)
|
|
|
+ message = bbs_message(base, msgno)
|
|
|
return message
|
|
|
|
|
|
|
|
@@ -142,7 +211,9 @@ def display_ansi(area, msgno):
|
|
|
return "RATS", 404
|
|
|
if not "text" in message:
|
|
|
return "RATS", 404
|
|
|
- png = ansi_to_png(message["bytes"].replace(b"\r", b"\n"), msgno)
|
|
|
+ # png = ansi_to_png(message["bytes"].replace(b"\r", b"\n"), msgno)
|
|
|
+ png = ansi_to_png(message["bytes"], msgno)
|
|
|
+ # png = ansi_to_png(message["bytes"].replace("\r", "\n"), msgno)
|
|
|
response = make_response(png)
|
|
|
response.headers.set("Content-Type", "image/png")
|
|
|
return response
|
|
@@ -156,7 +227,7 @@ def display_message(area, msgno):
|
|
|
"missing-area.html", base_path=base_path, title="Missing Area"
|
|
|
)
|
|
|
|
|
|
-# message = jammin.read_message(bases[area], msgno)
|
|
|
+ # message = jammin.read_message(bases[area], msgno)
|
|
|
message = get_message(bases[area], msgno)
|
|
|
|
|
|
if not message:
|
|
@@ -168,13 +239,26 @@ def display_message(area, msgno):
|
|
|
)
|
|
|
|
|
|
messages = get_messages(bases[area])
|
|
|
- total = len(messages)
|
|
|
+ # prevmsg and nextmsg are completely different now.
|
|
|
+
|
|
|
prevmsg = None
|
|
|
nextmsg = None
|
|
|
- if (msgno > 1):
|
|
|
- prevmsg = msgno - 1
|
|
|
- if (msgno < total):
|
|
|
- nextmsg = msgno + 1
|
|
|
+ total = len(messages)
|
|
|
+
|
|
|
+ for idx, msg in enumerate(messages):
|
|
|
+ if msg["MsgNum"] == msgno:
|
|
|
+ # Ok, found what we're looking for
|
|
|
+ if idx > 0:
|
|
|
+ prevmsg = messages[idx - 1]["MsgNum"]
|
|
|
+ if idx + 1 < total:
|
|
|
+ nextmsg = messages[idx + 1]["MsgNum"]
|
|
|
+
|
|
|
+ # prevmsg = None
|
|
|
+ # nextmsg = None
|
|
|
+ # if msgno > 1:
|
|
|
+ # prevmsg = msgno - 1
|
|
|
+ # if msgno < total:
|
|
|
+ # nextmsg = msgno + 1
|
|
|
|
|
|
if "text" in message:
|
|
|
if "\x1b" in message["text"]:
|
|
@@ -186,8 +270,14 @@ def display_message(area, msgno):
|
|
|
else:
|
|
|
text = message["text"].replace("\r", "\n")
|
|
|
# Ok, latest changes aren't doing word-wrap for us, so do it here.
|
|
|
- text = "\n".join( [ textwrap.fill(txt, width=78, replace_whitespace=False) for txt in text.splitlines()] )
|
|
|
- message["text"] = text; # message["text"].replace("\r", "\n") # <br >\n")
|
|
|
+ text = "\n".join(
|
|
|
+ [
|
|
|
+ textwrap.fill(txt, width=78, replace_whitespace=False)
|
|
|
+ for txt in text.splitlines()
|
|
|
+ ]
|
|
|
+ )
|
|
|
+ message["text"] = text
|
|
|
+ # message["text"].replace("\r", "\n") # <br >\n")
|
|
|
|
|
|
return render_template(
|
|
|
"message.html",
|