-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
117 lines (87 loc) · 3.45 KB
/
main.py
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
""" This is a simple program, to get user credentials and write them to a file ie. contacts file."""
from send_notification import notifications
from db_utils import db_connect, get_data
from plot_data import graph
from colorama import Fore, Back, Style
import time
#from soilmoisture import read_soil_moisture
file_containing_data = 'contacts.txt'
water_level = []
def add_users():
#Function to write data to an external file for storage.
file_containing_data = "contacts.txt"
fullname = input("Enter your full name: ")
email_address = input("Enter your email address: ")
phone_number = input("Enter your phone number: ")
#Writing user data to file NB:Will implement databases later.
file = open(file_containing_data, "a+")
#Writing to file.
file.write(fullname + "," + email_address + "," + phone_number + "\r\n")
file.close()
def remove_users():
#Function to remove user data from external file storage.
"""This can be achieved by reading the lines in the file and
then rewriting it provided it does not have match a given condition."""
name = input(Fore.RED + "Enter name of user you want to remove: ")
with open(file_containing_data, "r") as file:
lines = file.readlines()
with open(file_containing_data, "w") as file:
for line in lines:
if name not in line:
file.write(line)
def menu():
print(Fore.YELLOW + "==============MENU=============")
print(Fore.GREEN + "(1) Add or Remove Users. !")
print(Fore.GREEN + "(2) Current Tank Data. !")
print(Fore.GREEN + "(3) Settings & Configuration !")
print(Fore.YELLOW + "===============================")
print("")
return(int(input(Fore.YELLOW + "Choice: ")))
def get_tank_data():
""" Retrieving data from the tank."""
results = get_data(db_connect())
dates = []
for row in results:
dates.append(row['data'])
water_level.append(int(row['water_level']))
graph(water_level, dates)
def setting_and_configuration():
print("settings and let user decide what to do.\n\r")
def interface():
if choice == 1:
print(Fore.YELLOW + "\n\r============OPTIONS=============")
print(Fore.GREEN + "(1) Add user. ")
print(Fore.GREEN + "(2) Remove user.")
print(Fore.YELLOW + "================================")
print("")
sub_choice = int(input("Choice: "))
if (sub_choice == 1):
#Adding new user information.
add_users()
elif (sub_choice == 2):
#Removing exisiting user information
print(Fore.RED + "Typing a users name will remove them from data file.\n\r")
time.sleep(2)
print("")
remove_users()
else:
print(Fore.RED + "Input not recognised. \r\nTry again.")
print("")
elif choice == 2:
print(Fore.GREEN + "Graphing water levels...\n\r")
time.sleep(2)
get_tank_data()
print("Current Water Level Is: " + str(water_level[len(water_level)-1]))
print("")
print(Fore.GREEN + "Sending SMS & EMAIL notificationss.\n\r")
time.sleep(2)
notifications()
elif choice == 3:
print("")
setting_and_configuration()
print("")
else:
print(Fore.RED + "Input not recognised. \r\nTry again")
while True:
choice = menu()
interface()