Advertisement
anugerahsatria

Untitled

Mar 23rd, 2020
2,562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import requests
  2. import Adafruit_DHT
  3. import time
  4. import csv
  5. import sys
  6. csvfile = "temp.csv"
  7. als = True
  8. API_ENDPOINT = "://pastebin.com/api/api_post.php"
  9. API_KEY = "63d8b228fe6349b0fae90c609f42e95a"
  10. source_code = '''
  11. while als:
  12.    humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.DHT11, 21) # gpio pin 4 or pin number 7
  13.    if humidity is not None and temperature is not None:
  14.      humidity = round(humidity, 2)
  15.      temperature = round(temperature, 2)
  16.      print 'Temperature = {0:0.1f}*C  Humidity = {1:0.1f}%'.format(temperature, humidity)
  17.    else:
  18.      print 'can not connect to the sensor!'
  19.    timeC = time.strftime("%I")+':' +time.strftime("%M")+':'+time.strftime("%S")
  20.    data = [temperature, timeC]
  21.  
  22.    with open(csvfile, "a")as output:
  23.        writer = csv.writer(output, delimiter=",", lineterminator = '\n')
  24.        writer.writerow(data)
  25.    time.sleep(6) # update script every 60 seconds '''
  26.    
  27.     data = {'api_dev_key':API_KEY,
  28.         'api_option':'paste',
  29.         'api_paste_code':source_code,
  30.         'api_paste_format':'python'}  
  31.        
  32.     r = requests.post(url = API_ENDPOINT, data = data)
  33.     pastebin_url = r.text
  34.     print("The pastebin URL is:%s"%pastebin_url)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement