fix the write file compatibility on windows platform.
parent
ef9585ce8a
commit
940f1ddebf
|
@ -28,7 +28,7 @@ import asyncio
|
||||||
import tornado
|
import tornado
|
||||||
from tornado.web import Application
|
from tornado.web import Application
|
||||||
|
|
||||||
CONST_APP_VERSION = "MaxBot (2023.07.08)"
|
CONST_APP_VERSION = "MaxBot (2023.07.09)"
|
||||||
|
|
||||||
CONST_MAXBOT_QUESTION_FILE = "MAXBOT_QUESTION.txt"
|
CONST_MAXBOT_QUESTION_FILE = "MAXBOT_QUESTION.txt"
|
||||||
|
|
||||||
|
@ -227,20 +227,25 @@ def web_server():
|
||||||
|
|
||||||
def preview_question_text_file():
|
def preview_question_text_file():
|
||||||
if os.path.exists(CONST_MAXBOT_QUESTION_FILE):
|
if os.path.exists(CONST_MAXBOT_QUESTION_FILE):
|
||||||
question_text = ""
|
infile = None
|
||||||
with open(CONST_MAXBOT_QUESTION_FILE, "r") as text_file:
|
if platform.system() == 'Windows':
|
||||||
question_text = text_file.readline()
|
infile = open(CONST_MAXBOT_QUESTION_FILE, 'r', encoding='UTF-8')
|
||||||
|
else:
|
||||||
|
infile = open(CONST_MAXBOT_QUESTION_FILE, 'r')
|
||||||
|
|
||||||
global txt_question
|
if not infile is None:
|
||||||
try:
|
question_text = infile.readline()
|
||||||
displayed_question_text = txt_question.get("1.0",END).strip()
|
|
||||||
if displayed_question_text != question_text:
|
global txt_question
|
||||||
# start to refresh
|
try:
|
||||||
txt_question.delete("1.0","end")
|
displayed_question_text = txt_question.get("1.0",END).strip()
|
||||||
if len(question_text) > 0:
|
if displayed_question_text != question_text:
|
||||||
txt_question.insert("1.0", question_text)
|
# start to refresh
|
||||||
except Exception as exc:
|
txt_question.delete("1.0","end")
|
||||||
pass
|
if len(question_text) > 0:
|
||||||
|
txt_question.insert("1.0", question_text)
|
||||||
|
except Exception as exc:
|
||||||
|
pass
|
||||||
|
|
||||||
def text_server_timer():
|
def text_server_timer():
|
||||||
while True:
|
while True:
|
||||||
|
|
Loading…
Reference in New Issue