-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathching.py
More file actions
136 lines (115 loc) · 4.02 KB
/
ching.py
File metadata and controls
136 lines (115 loc) · 4.02 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
from datetime import datetime, timedelta
import os
money = 0
attempt_amount = 0
AddMoneyAccess = True
# Initialize money.txt if it doesn’t exist or contains invalid data
def __initialize_money_file():
global money
if not os.path.exists("money.txt"):
with open("money.txt", "w") as file:
file.write("0\n")
with open("money.txt", "r") as file:
first_line = file.readline().strip()
if first_line.isdigit():
money = int(first_line)
else:
money = 0 # Reset invalid data
__update_money_file()
# Update the money amount in money.txt
def __update_money_file():
with open("money.txt", "w") as file:
file.write(f"{money}\n")
# Add money (if access is allowed)
def addmoney(moneytoadd):
global money
if AddMoneyAccess:
money += moneytoadd
__update_money_file()
else:
print("Access to addmoney() is blocked for this session.")
# Subtract money from allowance
def minusmoney(moneytominus):
global money
money -= moneytominus
__update_money_file()
# Show the current money balance
def printmoney():
if AddMoneyAccess:
print(money)
else:
print("Access to printmoney() is blocked for this session.")
# Log today’s date in logfile.txt (used for tracking allowances)
def getdate():
current_date = datetime.now().strftime("%Y-%m-%d")
if os.path.exists("logfile.txt"):
with open("logfile.txt", "r") as file:
lines = file.readlines()
else:
lines = []
if lines:
lines[0] = f"{current_date}\n"
else:
lines.append(f"{current_date}\n")
with open("logfile.txt", "w") as file:
file.writelines(lines)
# Get the last recorded date from logfile.txt
def finddate():
try:
with open("logfile.txt", "r") as file:
first_line = file.readline().strip()
return first_line if first_line else None
except FileNotFoundError:
return None
# Check if it's time to receive income based on a given interval
def incomedate(date, interval):
global money
try:
given_date = datetime.strptime(date, "%Y-%m-%d")
except ValueError:
print("Invalid date format. Use YYYY-MM-DD.")
return
today = datetime.now()
intervals = {
"daily": today,
"weekly": today - timedelta(weeks=1),
"hourly": today - timedelta(hours=1),
"yearly": today - timedelta(days=365),
}
comparison_date = intervals.get(interval)
if not comparison_date:
print("Invalid interval specified.")
return
if given_date >= comparison_date:
print(f"You received your {interval} income!")
money += 100
__update_money_file()
else:
print("No income yet.")
# Give weekly allowance on a specified weekday (but only once per day)
def allowance(weekday):
global money
today_weekday = datetime.now().strftime("%A").lower()
last_allowance_date = finddate()
if today_weekday == weekday.lower():
if last_allowance_date != datetime.now().strftime("%Y-%m-%d"):
print("It's allowance day! 💰")
money += 50
__update_money_file()
getdate()
else:
print("Allowance already given today.")
# Prevent the balance from exceeding a set limit & restrict access after too many attempts
def limitmoney(moneylimit):
global money, attempt_amount, AddMoneyAccess
if money > moneylimit:
money = moneylimit
print("Money limit exceeded, automatically adjusted.")
attempt_amount += 1
print(f"Attempt logged. Attempts so far: {attempt_amount}")
if attempt_amount >= 5:
money = moneylimit
print("Money limit reached. Access to printmoney() and addmoney() is now denied.")
AddMoneyAccess = False
# Initialize money file when script runs
__initialize_money_file()