-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlimit_handler.py
More file actions
30 lines (24 loc) · 1009 Bytes
/
Copy pathlimit_handler.py
File metadata and controls
30 lines (24 loc) · 1009 Bytes
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
from datetime import datetime
import os.path
class LimitHandler:
def getCurrentUsage():
currentDate = datetime.today().strftime('%Y-%m-%d')
if not os.path.exists("data/{}.data".format(currentDate)):
file = open("data/{}.data".format(currentDate), mode = "w+")
file.write("0")
file.close()
file = open("data/{}.data".format(currentDate), mode = "r+")
return int(file.read())
def incrementUsage():
currentDate = datetime.today().strftime('%Y-%m-%d')
if not os.path.exists("data/{}.data".format(currentDate)):
file = open("data/{}.data".format(currentDate), mode = "w+")
file.write("0")
file.close()
file = open("data/{}.data".format(currentDate), mode = "r+")
data = int(file.read())
data += 1
file.close()
file = open("data/{}.data".format(currentDate), mode = "w")
file.write(str(data))
file.close()