Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #These are the imports google said to include
- import gdata.calendar.service
- import gdata.service
- import atom.service
- import gdata.calendar
- import gdata.calendar
- import atom
- import getopt
- import sys
- import string
- import time
- import urllib2
- import MySQLdb
- import xe #for the time comparator
- from feed.date.rfc3339 import tf_from_timestamp #also for the comparator
- from datetime import datetime #for the time on the rpi end
- from apscheduler.scheduler import Scheduler #this will let us check the calender on a regular interval
- import os, random #to play the mp3 later
- #this is more stuff google told me to do, but essentially it handles the login credentials
- calendar_service = gdata.calendar.service.CalendarService()
- calendar_service.password = 'password' #your password
- calendar_service.source = 'Google-Calendar_Python_Sample-1.0'
- calendar_service.ProgrammaticLogin()
- def checkCalendarEvent(calendar_service, text_query, status, id):
- print 'Full text query for events on Primary Calendar: \'%s\'' % ( text_query,)
- query = gdata.calendar.service.CalendarEventQuery('default', 'private', 'full', text_query)
- feed = calendar_service.CalendarQuery(query)
- for i, an_event in enumerate(feed.entry):
- for a_when in an_event.when:
- print "---"
- print "id=%i,status=%s,sort=%s" % (id, status, text_query)
- print an_event.title.text ,"Number:",i,"Event Time:",time.strftime('%d-%m-%Y %H:%M',time.localtime(tf_from_timestamp(a_when.start_time))),"Current Time:",time.strftime('%d-%m-%Y %H:%M')
- print an_event.title.text ,"Number:",i,"Event Time:",time.strftime('%d-%m-%Y %H:%M',time.localtime(tf_from_timestamp(a_when.end_time))),"Current Time:",time.strftime('%d-%m-%Y %H:%M')
- if time.strftime('%d-%m-%Y %H:%M',time.localtime(tf_from_timestamp(a_when.start_time))) == time.strftime('%d-%m-%Y %H:%M'):
- print "Comparison: Pass"
- print "---"
- url1 = "http://192.168.170.13:400/calendar/request.php?s="+ str(id) + "_on"
- urllib2.urlopen(url1).read()
- if time.strftime('%d-%m-%Y %H:%M',time.localtime(tf_from_timestamp(a_when.end_time))) == time.strftime('%d-%m-%Y %H:%M'):
- print "Comparison: Pass"
- print "---"
- url1 = "http://192.168.170.13:400/calendar/request.php?s="+ str(id) + "_off"
- urllib2.urlopen(url1).read()
- if time.strftime('%d-%m-%Y %H:%M',time.localtime(tf_from_timestamp(a_when.end_time))) == time.strftime('%d-%m-%Y %H:%M'):
- print "Comparison: Pass"
- print "---"
- def ReloadDatabase():
- # Open database connection
- db = MySQLdb.connect("localhost","jochim","LUZtfrGU3NnqyfTh","pi_home" )
- # prepare a cursor object using cursor() method
- cursor = db.cursor()
- # prepare a cursor object using cursor() method
- cursor = db.cursor()
- # Prepare SQL query to INSERT a record into the database.
- sql = "SELECT * FROM pi_devices "
- try:
- # Execute the SQL command
- cursor.execute(sql)
- # Fetch all the rows in a list of lists.
- results = cursor.fetchall()
- for row in results:
- id = row[0]
- device = row[2]
- status = row[5]
- sort = row[6]
- aktiv = row[7]
- checkCalendarEvent(calendar_service, sort, status, id)
- # Now print fetched result
- #print "id=%i,device=%s,status=%s,sort=%s,aktiv=%s" % \
- #(id, device, status, sort, aktiv )
- except:
- print "Error: unable to fecth data"
- # disconnect from server
- db.close()
- def callable_func():
- os.system("clear") #this is more for my benefit and is in no way necesarry
- print "------------start-----------"
- ReloadDatabase()
- #FullTextQuery1(calendar_service)
- print "-------------end------------"
- scheduler = Scheduler(standalone=True)
- scheduler.add_interval_job(callable_func,seconds=5)
- scheduler.start() #runs the program indefinatly on an interval of 5 seconds
Add Comment
Please, Sign In to add comment