flake8 format

main
Bob Mottram 2020-04-04 11:12:34 +01:00
parent da3900c9f1
commit 3334cc0466
1 changed files with 46 additions and 37 deletions

View File

@ -11,7 +11,9 @@ from utils import locatePost
from utils import loadJson
from utils import saveJson
def questionUpdateVotes(baseDir: str,nickname: str,domain: str,replyJson: {}) -> {}:
def questionUpdateVotes(baseDir: str, nickname: str, domain: str,
replyJson: {}) -> {}:
""" For a given reply update the votes on a question
Returns the question json object if the vote totals were changed
"""
@ -64,14 +66,18 @@ def questionUpdateVotes(baseDir: str,nickname: str,domain: str,replyJson: {}) ->
# create a new voters file
votersFile = open(votersFilename, "w")
if votersFile:
votersFile.write(replyJson['actor']+votersFileSeparator+foundAnswer+'\n')
votersFile.write(replyJson['actor'] +
votersFileSeparator +
foundAnswer + '\n')
votersFile.close()
else:
if replyJson['actor'] not in open(votersFilename).read():
# append to the voters file
votersFile = open(votersFilename, "a+")
if votersFile:
votersFile.write(replyJson['actor']+votersFileSeparator+foundAnswer+'\n')
votersFile.write(replyJson['actor'] +
votersFileSeparator +
foundAnswer + '\n')
votersFile.close()
else:
# change an entry in the voters file
@ -80,8 +86,10 @@ def questionUpdateVotes(baseDir: str,nickname: str,domain: str,replyJson: {}) ->
newlines = []
saveVotersFile = False
for voteLine in lines:
if voteLine.startswith(replyJson['actor']+votersFileSeparator):
newVoteLine=replyJson['actor']+votersFileSeparator+foundAnswer+'\n'
if voteLine.startswith(replyJson['actor'] +
votersFileSeparator):
newVoteLine = replyJson['actor'] + \
votersFileSeparator + foundAnswer + '\n'
if voteLine == newVoteLine:
break
saveVotersFile = True
@ -103,7 +111,8 @@ def questionUpdateVotes(baseDir: str,nickname: str,domain: str,replyJson: {}) ->
with open(votersFilename, "r") as votersFile:
lines = votersFile.readlines()
for voteLine in lines:
if voteLine.endswith(votersFileSeparator+possibleAnswer['name']+'\n'):
if voteLine.endswith(votersFileSeparator +
possibleAnswer['name'] + '\n'):
totalItems += 1
if possibleAnswer['replies']['totalItems'] != totalItems:
possibleAnswer['replies']['totalItems'] = totalItems