-
Notifications
You must be signed in to change notification settings - Fork 1
/
auto.py
45 lines (37 loc) · 1.38 KB
/
auto.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
from datetime import datetime
from random import choice
from temperature import *
LOG_FILE = 'temp.log'
def hasDeclared(tempData):
lastDeclaredDate = tempData[0][1].split(', ')[0]
todayDate = datetime.now().strftime('%d/%m/%Y')
if lastDeclaredDate != todayDate: return False
lastTempAM = tempData[0][2]
lastTempPM = tempData[0][5]
isAM = datetime.now().hour < 12
if isAM: return lastTempAM != ''
else: return lastTempPM != ''
def getRandomTemperature():
temp = choice(range(360, 372)) / 10
tempStr = '%.1f' % temp
return tempStr
def logMessage(msg):
with open(LOG_FILE, 'a') as f:
f.write('%s' % msg)
if __name__ == '__main__':
logMessage('[%s] ' % datetime.now().strftime('%d/%m/%y %H:%M:%S'))
username, password = readUsernamePassword()
try:
jsessionID = login(username, password)
except Exception as e:
logMessage('Your login credentials are invalid\n')
exit()
tempResponseText = getTemperature(jsessionID)
tempData = parseTemperatureTable(tempResponseText)
if hasDeclared(tempData):
logMessage('Already declared temperature\n')
else:
temperature = getRandomTemperature()
tempResponseText = submitTemperature(jsessionID, temperature)
tempData = parseTemperatureTable(tempResponseText)
logMessage('Submitted temperature of %s°C\n' % temperature)