Code : Call other file
- import os
- os.system('filename.py')
Example :
- os.system('/home/pi/checkair.py')
Code : Time Delay
- import time
- while True:
- print "This prints once a minute."
- time.sleep(60) # Delay for 1 minute (60 seconds)
Example : All
- #!/usr/bin/python
- #### Check temperature Adafruit_DHT 22 23 #######
- import sys
- import os
- import Adafruit_DHT
- import time
- humidity, temperature = Adafruit_DHT.read_retry(22, 23)
- #while(humidity is None and temperature is None):
- while(temperature is None):
- humidity, temperature = Adafruit_DHT.read_retry(22, 23)
- time.sleep(10) # Delay for 10 seconds before loop.
- #### On Or Off Relay By Piface #####
- import pifacedigitalio
- pf = pifacedigitalio.PiFaceDigital()
- import smtplib
- print 'Temp={0:0.1f}* Humidity={1:0.1f}%'.format(temperature, humidity)
- if temperature > 27:
- pf.relays[1].turn_on()
- pf.relays[0].turn_on()
- from smtplib import SMTP
- recipients = ['suwit.jph@gmail.com', '"komkid@gmail.com', 'nontiwaza@gmail.com']
- def send_email (message, status):
- fromaddr = 'scivalve.suwit@gmail.com'
- server = SMTP('smtp.gmail.com:587')
- server.ehlo()
- server.starttls()
- server.ehlo()
- server.login('scivalve.suwit@gmail.com', 'PASSWORD')
- server.sendmail(fromaddr, recipients, 'Subject: %s\r\n%s' % (status, message))
- server.quit()
- send_email("High temp alert! in Server Room A. " '{0:0.1f}*C'.format(temperature), "High temp alert! Turn ON relays.")
- else:
- pf.relays[0].turn_off()
- pf.relays[1].turn_off()
- pf.deinit_board()
http://stackoverflow.com/questions/7974849/how-can-i-make-one-python-file-run-another
No comments:
Post a Comment