Python-i script käivitamine crontabiga
Postitatud: 19.09.2013, 08:09
Proovisin igati aga ei saanudki käima. Tegemist Debian Wheezi ARM-ga
Kood: Vali kõik
*/10 * * * * /usr/bin/python /sinu/skript/skript.py &Kood: Vali kõik
#!/usr/bin/python
import subprocess
import re
import sys
import time
import datetime
import gspread
# ===========================================================================
# Google Account Details
# ===========================================================================
# Account details for google docs
email = 'you@somewhere.com'
password = '$hhh!'
spreadsheet = 'SpreadsheetName'
# ===========================================================================
# Example Code
# ===========================================================================
# Login with your Google account
try:
gc = gspread.login(email, password)
except:
print "Unable to log in. Check your email address/password"
sys.exit()
# Open a worksheet from your spreadsheet using the filename
try:
worksheet = gc.open(spreadsheet).sheet1
# Alternatively, open a spreadsheet using the spreadsheet's key
# worksheet = gc.open_by_key('0BmgG6nO_6dprdS1MN3d3MkdPa142WFRrdnRRUWl1UFE')
except:
print "Unable to open the spreadsheet. Check your filename: %s" % spreadsheet
sys.exit()
# Continuously append data
# while(True) asemele loendur
count = 0
while count < 1:
# Run the DHT program to get the humidity and temperature readings!
output = subprocess.check_output(["./Adafruit_DHT", "2302", "4"]);
print output
matches = re.search("Temp =\s+([0-9.]+)", output)
if (not matches):
time.sleep(3)
continue
temp = float(matches.group(1))
# search for humidity printout
matches = re.search("Hum =\s+([0-9.]+)", output)
if (not matches):
time.sleep(3)
continue
humidity = float(matches.group(1))
print "Temperature: %.1f C" % temp
print "Humidity: %.1f %%" % humidity
# Append the data in the spreadsheet, including a timestamp
try:
values = [datetime.datetime.now(), temp, humidity]
worksheet.append_row(values)
except:
print "Unable to append data. Check your connection?"
sys.exit()
#käsk täidetud, skripti seiskamine
count = count +1
else:
sys.exit()
Ei hakka tõesti, sest on mõned vead:obundra kirjutas:ei garanteeri, et tööle hakkab, testimine omal vastutusel.