in pysteve/lib/backends/files.py [0:0]
def vote(self, electionID, issueID, uid, vote):
"Casts a vote on an issue"
votes = {}
now = time.time()
issuepath = os.path.join(self.homedir, "issues", electionID, issueID) + ".json"
if os.path.isfile(issuepath + ".votes"):
with open(issuepath + ".votes", "r") as f:
votes = json.loads(f.read())
f.close()
votes[uid] = {
'vote': vote,
'timestamp': now
}
with open(issuepath + ".votes", "w") as f:
f.write(json.dumps(votes))
f.close()
# history backlog
vote_history = []
issuepath = os.path.join(self.homedir, "issues", electionID, issueID) + ".json"
if os.path.isfile(issuepath + ".history"):
with open(issuepath + ".history", "r") as f:
vote_history = json.loads(f.read())
f.close()
vote_history.append({
'key': uid,
'data': {
'vote': vote,
'timestamp': now
}
})
with open(issuepath + ".history", "w") as f:
f.write(json.dumps(vote_history))
f.close()