-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
117 lines (65 loc) · 2.13 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
'''
Author: Maxwell Cofie
Project: backyard.io
Date Started: 10th Agust 2017
'''
#imports
import uuid
import pymysql
import urllib as url
hostname = 'localhost'
username = 'root'
password = 'boss1234'
database = 'backyard_io'
con = pymysql.connect( hostname, username, password, database )
def init( conn ):
cur = conn.cursor()
cur.execute( "SELECT * FROM account_details limit 1" )
if(len(cur.fetchall()) == 0):
set_up(conn)
else:
print "You're most welcome!"
status(conn)
def set_up(conn):
cur = conn.cursor()
print ("Welcome to backyard.io")
first_name = raw_input("Please enter Firstname: ")
last_name = raw_input("Please enter Lastname: ")
country = raw_input("Country: ")
pass_word = raw_input("Password: ")
location = raw_input("City: ")
username = generate_token(7)
query = "insert into account_details (first_name,last_name,username, pass_word, location, country) values (%s,%s,%s,%s,%s,%s)"
cur.execute(query,(first_name,last_name,username,pass_word,location,country))
conn.commit()
def authentication(user_name,pass_word):
if(username == user_name and password == pass_word):
return True
else:
return False
def status(conn):
cur = conn.cursor()
cur.execute( "SELECT username FROM account_details limit 1" )
access_token = cur
for i in cur:
print 'Access Token :', i[0] +"'\n" + 'Soil moisture : ', get_soil_moisture()+"\n"+'Soil Temperature : ',get_soil_temperature()+"\n"+ 'Light Intensity : ',get_light_intensity()+"\n"+network_status()
def get_soil_moisture():
return "940 vol" #temporary placeholders
def get_soil_temperature():
return "13 Celcius" #temporary placeholders
def get_light_intensity():
return "89 lx" #temporary placeholders
def generate_token(size=7):
random = str(uuid.uuid4())
random = random.upper()
random = random.replace("-","")
return random[0:size]
def network_status():
try:
url.request.urlopen("https//:google.com")
return "Active Connection"
except:
return "Connection Failed"
#Call Main Function
init( con )
con.close()