This repository was archived by the owner on Dec 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
48 lines (42 loc) · 1.68 KB
/
utils.py
File metadata and controls
48 lines (42 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""
Utilities to keep main app small
and easier to develop.
Contain functions to read and write files
and will be extended.
"""
import os # used to check if file exist
import datetime # give access to actual date and time functions
def read_backup():
"""
read backup_money value from a file
and if there is none it is created
"""
if os.path.isfile(os.path.join(os.path.dirname(__file__), 'data/backup_money.txt')): # check if file exist
myfile = open(os.path.join(os.path.dirname(__file__), 'data/backup_money.txt'), 'r') # open to read
backup_money = myfile.read() # takes the value of backup
myfile.close
else: # if file don't exist backup = 0
backup_money = 0
if backup_money == '': # make sure if file is empty that it returns zero
backup_money = 0
backup_coins = int(backup_money) # make sure backup_coins value is integer
return backup_coins
def write_backup(self):
"""
rewrites value of backup_money
"""
myfile = open(os.path.join(os.path.dirname(__file__), 'data/backup_money.txt'), 'w+')
myfile.write(self.e13.get())
myfile.close
def save_result(stav_kasy, rozdil_trzby):
"""
takes the result from calculation,
creates new file with actual date and time
or append existing one with line
containing date, time, reference value and difference
"""
now = datetime.datetime.now()
datum = now.strftime("%d.%m.%Y %H:%M")
myfile = open(os.path.join(os.path.dirname(__file__), 'data/archive.txt'), 'a')
myfile.write("%-19s%-11s%-7s%-14s%-7s%-1s" % (datum, 'Stav kasy: ', str(stav_kasy), 'Rozdíl tržby: ', str(rozdil_trzby), '\n'))
myfile.close