title: how can i execute python code every hour
body: <p>I'm working on a "WeatherLogger" app that will create a log file every hour/day.
  This is my code:</p>
  
  <pre><code>import Adafruit_DHT as dht
  import RPi.GPIO as GPIO
  import time
  import os
  GPIO.setmode(GPIO.BCM)
  rainsensorpin = "4"
  GPIO.setup(rainsensorpin, GPIO.IN)
  def log():
          print "[!] Log action executed, processing it..."
          filename = time.strftime('%d%Y-%m-%d %H:%M:%S')
          humidity, temperature = Adafruit_DHT.read_retry(sensor,pin)
          temp = "{:0.1f}*C".format(temperature)
          hum = "{:0.1f}%".format(humidity)
          state = GPIO.input(rainsensorpin)
          data = "Temp: ", temp, " Hum: ", hum, " Rain: ", state, " Date+Time: ", filename
          os.chdir("logs")
          os.mknod(filename)
          print "[+] Successfully created file: ", filename
  </code></pre>
  
  <p>Is there any way to execute this code every hour, or every day?</p>