Skip to content

Commit

Permalink
Bingo Viewer now ignores errors when trying to read the file more
Browse files Browse the repository at this point in the history
gracefully.  Readd the ability to push JSON information about bingo
state.
  • Loading branch information
theastropath committed Oct 24, 2023
1 parent 07a5785 commit f6ce619
Showing 1 changed file with 31 additions and 24 deletions.
55 changes: 31 additions & 24 deletions BingoDisplay.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import argparse
import time
import sys
import json
import os.path
import urllib.request
import urllib.parse
import re
from tkinter import filedialog as fd
from tkinter import font
Expand Down Expand Up @@ -144,7 +147,7 @@ def parseBingoLine(self,bingoLine):
bingoMatches=self.bingoLineMatch.match(bingoLine)
if (bingoMatches==None):
return

bingoNumber=int(bingoMatches.group('key'))
bingoCoord = self.bingoNumberToCoord(bingoNumber)

Expand All @@ -160,8 +163,12 @@ def parseBingoLine(self,bingoLine):
def readBingoFile(self):
allLines = dict()
try:
with open(self.targetFile) as file:
bingoFile = file.readlines()
try:
with open(self.targetFile) as file:
bingoFile = file.readlines()
except Exception as e:
print("Couldn't read file, ignoring - "+str(e));
return False

for line in bingoFile:
if BINGO_MOD_LINE_DETECT in line:
Expand Down Expand Up @@ -216,29 +223,29 @@ def generateBingoStateJson(self):
square["possible"]=self.board[x][y]["active"]!=-1
#print(square)
board.append(square)
#return {"bingo":json.dumps({"bingo":board},indent=4)}
#return json.dumps(board,indent=4)
return {"bingo":json.dumps({"bingo":board},indent=4)}

def sendBingoState(self):
pass
# if not os.path.isfile(JSON_DEST_FILENAME):
# return

# f = open(JSON_DEST_FILENAME,'r')
# desturl=f.readline()
# f.close()

# if (desturl==""):
# print("Make sure to specify where you want to push your json!")
# return

# bingoState = self.generateBingoStateJson()
# #print(bingoState)
# try:
# r = urllib.request.urlopen(desturl,data=urllib.parse.urlencode(bingoState).encode('utf-8'))
# #print(r.status)
# #print(r.read().decode('utf-8'))
# except Exception as e:
# print("Couldn't push JSON to "+desturl+" - "+str(e))
if not os.path.isfile(JSON_DEST_FILENAME):
return

f = open(JSON_DEST_FILENAME,'r')
desturl=f.readline()
f.close()

if (desturl==""):
print("Make sure to specify where you want to push your json!")
return

bingoState = self.generateBingoStateJson()
#print(bingoState)
try:
r = urllib.request.urlopen(desturl,data=urllib.parse.urlencode(bingoState).encode('utf-8'))
#print(r.status)
#print(r.read().decode('utf-8'))
except Exception as e:
print("Couldn't push JSON to "+desturl+" - "+str(e))


def saveLastUsedBingoFile(f):
Expand Down

0 comments on commit f6ce619

Please sign in to comment.