title: Python how to check if database value is the same
body: <p>Hello I have this firebase set up that is connected to a raspberry pi that speaks text according the firebase database.  I have the function running every 5 seconds, and I'd like to check if there is a new message.  I store the time of each message in the database, and the way i have it going now is that it's checking to see if the time is the same on new and old messages.</p>
  
  <p>My two questions are:</p>
  
  <p>Is there a better way to checking the messages time, to see if messages are new?</p>
  
  <p>How can I fix this code so I am not getting a <code>UnboundLocalError: local variable 'the_time' referenced before assignment"</code> error</p>
  
  <p>Here is my code</p>
  
  <pre><code>import time
  import subprocess
  from firebase import firebase
  firebase = firebase.FirebaseApplication('----', None)
  
  message = firebase.get('/message', None)
  name = firebase.get('/name', None)
  the_time = firebase.get('the_time',None)
  speak_message = message+" from "+ name
  
  def showmessage():
          message=firebase.get('/message',None)
          name=firebase.get('/name',None)
          current_time = firebase.get('/the_time',None)
          speak_message=message+' from '+name
  
          #this is to set the audio jack on raspi
          subprocess.call(['amixer','cset','numid=3','1'])
  
          if current_time == the_time:
                  #message is NOT new
                  print 'message is NOT new'
  
          elif current_time != the_time:
                  #message IS new
                  #Shell script to run text-to-speech
                  subprocess.call(['/home/pi/./speech.sh',speak_message])
                  the_time = current_time
  
  
          time.sleep(5)
  while True:
          showmessage()
  </code></pre>