Permalink
Cannot retrieve contributors at this time
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?
Weather_Station/WeatherDrive.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
39 lines (31 sloc)
1.08 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time, socket, datetime, os, fcntl, struct, sqlite3 #import time, IP, time and date | |
from w1thermsensor import W1ThermSensor | |
localtime = time.asctime( time.localtime(time.time()) ) #Gets the time | |
print (" * Current time :" + str(localtime)) #Displays Time | |
from pydrive.auth import GoogleAuth | |
gauth = GoogleAuth() | |
gauth.LocalWebserverAuth() | |
drive = GoogleDrive(gauth) | |
def getTemperature(): | |
sensor = W1ThermSensor() | |
temperature = sensor.get_temperature() | |
return(temperature) | |
while True: | |
file1 = drive.CreateFile({'title': 'Weather.html'}) # Create GoogleDriveFile instance with title 'Hello.txt'. | |
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 >= 18: | |
B = "Warm.png" | |
elif 5 < T < 18: | |
B = "Cold.png" | |
elif 0 < T <= 5: | |
B = "rCold.png" | |
else: | |
B = "sCold.png" | |
upStr = (F.read() + B + M.read() + str(round(T, 1)) + "°C <h4> " + str(round(T, 2)) + "°C </h4>" + L.read()) | |
file1.SetContentString(upStr) # Set content of the file from given string. | |
file1.Upload() | |
GPIO.cleanup() |