Advertisement
Guest User

Untitled

a guest
Sep 8th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import Adafruit_DHT
  4. import psycopg2
  5. from time import strftime
  6.  
  7. DHT_MODEL = 11
  8. GPIO = 4
  9.  
  10. humidity, temperature = Adafruit_DHT.read_retry(DHT_MODEL, GPIO)
  11.  
  12. insert = ('INSERT INTO week_temp (temp, humidity, time) VALUES
  13. ({:.0f}, {:.0f}, \'{}\'::timestamp);'
  14. .format(temperature, humidity, strftime('%Y-%m-%d %H:%M:')))
  15.  
  16. try:
  17. connect = psycopg2.connect(database='db_name', user='user_name',
  18. host='ip_addr', password='passwd')
  19.  
  20. cursor = connect.cursor()
  21. cursor.execute(insert)
  22. connect.commit()
  23. connect.close()
  24. except:
  25. pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement