From 9c9a36635578ba1cdc5b36a12cb2d9873883fac4 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 22 Feb 2021 17:09:40 +0100 Subject: [PATCH] Added JSON file to manually set server. --- pesterchum.py | 52 ++++++++++++++++++++++++--------------------------- server.json | 3 +++ setup.py | 6 +----- 3 files changed, 28 insertions(+), 33 deletions(-) create mode 100644 server.json diff --git a/pesterchum.py b/pesterchum.py index 9586acf..ecb070b 100644 --- a/pesterchum.py +++ b/pesterchum.py @@ -13,6 +13,10 @@ import random import re from time import time import threading, Queue +try: + import json +except: + pass try: from pnc.attrdict import AttrDict except ImportError: @@ -3052,35 +3056,27 @@ class MainProgram(QtCore.QObject): options = self.oppts(sys.argv[1:]) - # Choose a server by qt message box. - # Writes the result to server.ini - - #msgBox = QtGui.QMessageBox() - #msgBox.setIcon(QtGui.QMessageBox.Information) - #msgBox.setWindowTitle("Please choose a server") - #msgBox.setText("Which server do you want to connect to?") - #msgBox.addButton(QtGui.QPushButton("irc.mindfang.org (Official)"), QtGui.QMessageBox.YesRole) - #msgBox.addButton(QtGui.QPushButton("pesterchum.xyz (Unofficial)"), QtGui.QMessageBox.NoRole) - # msgBox.addButton(QtGui.QPushButton('kaliope.ddns.net (Unofficial)'), QtGui.QMessageBox.RejectRole) - #ret = msgBox.exec_() - #reply = msgBox.buttonRole(msgBox.clickedButton()) - # Since there's currently no other working servers, all of this is commented out for now. - - self.server = "pesterchum.xyz" - print("Server is: pesterchum.xyz") - - #if (reply==QtGui.QMessageBox.YesRole): - # print("Server is: irc.mindfang.org") - # self.server = "irc.mindfang.org" - #if (reply==QtGui.QMessageBox.NoRole): - # print("Server is: pesterchum.xyz") - # self.server = "pesterchum.xyz" - #if (reply==QtGui.QMessageBox.RejectRole): - # print("Server is: kaliope.ddns.net") - # self.server = "kaliope.ddns.net" - - + # Tries to load the server to connect to from server.json. + # If it fails, create json file with default of pesterchum.xyz & connect to pesterchum.xyz + try: + with open("server.json", "r") as server_file: + read_file = server_file.read() + server_file.close() + server_obj = json.loads(read_file) + self.server = str(server_obj['server']) + except: + try: + with open("server.json", "w") as server_file: + json_server_file = { + "server": "pesterchum.xyz", + } + server_file.write(json.dumps(json_server_file, indent = 4) ) + server_file.close() + except: + pass + self.server = "pesterchum.xyz" + print("Server is: " + self.server) def doSoundInit(): # TODO: Make this more uniform, adapt it into a general function. diff --git a/server.json b/server.json new file mode 100644 index 0000000..fce98d0 --- /dev/null +++ b/server.json @@ -0,0 +1,3 @@ +{ + "server": "pesterchum.xyz" +} \ No newline at end of file diff --git a/setup.py b/setup.py index 2e743d1..447bbfb 100644 --- a/setup.py +++ b/setup.py @@ -3,10 +3,6 @@ from cx_Freeze import setup, Executable import sys import os import shutil -import requests -import urllib -import PyQt4 -from Queue import * if sys.platform == "win32": base = "Win32GUI" @@ -21,7 +17,7 @@ build_exe_options = { 'collections._locale', 'collections._struct', 'collections.array', - 'collections._weakref'], # Not excluding these is the only way I could get it to build while using configparser. I don't know why though. + 'collections._weakref'], } setup(