Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import time, socket, datetime, os, fcntl, struct, sqlite3 #import time, IP, time and date
from flask import Flask, render_template, request, jsonify, request, send_file #import web app
from w1thermsensor import W1ThermSensor
import netifaces as ni
#from weather import Weather, Unit
#weather = Weather(unit=Unit.CELSIUS)
#lookup = weather.lookup(560743)
global int_time
int_time = datetime.datetime.now()
app = Flask(__name__) #Assigns app
#os.system("sudo mount -t exfat /dev/sda1 /media/usb")
localtime = time.asctime( time.localtime(time.time()) ) #Gets the time
print (" * Current time :" + str(localtime)) #Displays Time
ni.ifaddresses('eth0')
IP = ni.ifaddresses('eth0')[ni.AF_INET][0]['addr']
def accessed():
F = open("A.txt", "r")
A = F.read()
F.close()
F = open("A.txt", "w")
F.write(str(int(A)+1))
F.close()
def getTemperature():
sensor = W1ThermSensor()
temperature = sensor.get_temperature()
#temperature = -1.29
return(temperature)
def makeWebpage():
#weather = Weather(unit=Unit.CELSIUS)
#lookup = weather.lookup(17044)
#wind = lookup.wind
W = open("templates/index.html", "w")
F = open("First.txt", "r")
M = open("Middle.txt", "r")
L = open("Last.txt", "r")
T = getTemperature()
if T >= 30:
B = "Hot.png"
elif 18 <= T < 30:
B = "Warm.png"
elif 5 < T < 18:
B = "Cold.png"
elif 0 < T <= 5:
B = "rCold.png"
else:
B = "sCold.png"
W.write(F.read() + B + M.read() + str(round(T, 1)) + "°C <h4> " + str(round(T, 2)) + "°C </h4> " + L.read())
accessed()
W.close()
F.close()
M.close()
L.close()
@app.route('/') #Sets index
def index():
makeWebpage()
return render_template('index.html') #Displays HTML page 'Relay.html'
@app.route('/about') #Sets index
def about():
Af = open("aF.txt", "r")
Al = open("aL.txt", "r")
Aw = open("templates/about.html", "w")
N = open("A.txt", "r")
Uptime = datetime.datetime.now() - int_time
Aw.write(Af.read() + "<p> <center> This Weather Station Has Been Used " + str(N.read()) + " Times </center> </p> <p> <center> Temperature (Up to 3dp): " + str(getTemperature()) + "°C </center> </p> <center> <p> Uptime: " + str(Uptime.days)+ " day(s), " + str(Uptime.seconds//3600) + " hour(s), "+ str(int((Uptime.seconds//60)%60)) + " minute(s) and " + str(int(Uptime.seconds%60)) + " second(s) </center>" + Al.read())
Af.close()
Al.close()
Aw.close()
N.close()
return render_template('about.html') #Displays HTML page 'Relay.html'
@app.route('/source') #Sets index
def source():
return send_file('Weather.py')
if __name__ == '__main__':
app.run(debug=True, host=(str(IP)), threaded=True, port=80)
GPIO.cleanup()