This Is A Custom Widget

This Sliding Bar can be switched on or off in theme options, and can take any widget you throw at it or even fill it with your custom HTML Code. Its perfect for grabbing the attention of your viewers. Choose between 1, 2, 3 or 4 columns, set the background color, widget divider color, activate transparency, a top border or fully disable it on desktop and mobile.

This Is A Custom Widget

This Sliding Bar can be switched on or off in theme options, and can take any widget you throw at it or even fill it with your custom HTML Code. Its perfect for grabbing the attention of your viewers. Choose between 1, 2, 3 or 4 columns, set the background color, widget divider color, activate transparency, a top border or fully disable it on desktop and mobile.

Raspberry Pi Project – Google Alarm Clock

 

If you happen to use Google Calendar quite a bit and also own a raspberry pi or pi2 you can make a neat alarm clock. The way the program works is that your pi will continuously check events on your google calendar and look for the start time of an event called “wake”. Once it finds that trigger you it will then play a random song off your hard drive and if you’re speakers are loud enough then wake you up. You can view¬†

 

The code for the script is as follows:
#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 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.email = ‘youremail@yourdomain’ #your email
calendar_service.password = ‘yourgcalpassword’ #your password
calendar_service.source = ‘Google-Calendar_Python_Sample-1.0′
calendar_service.ProgrammaticLogin()

def FullTextQuery(calendar_service, text_query=’wake’):
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 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’)

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 “—”

songfile = random.choice(os.listdir(“/home/pi/alarmclock/test_MP3s/”)) #chooses the .mp3 file
print “File Selected:”, songfile
command =”mpg321″ + ” ” + “/home/pi/alarmclock/test_MP3s/” + “‘”+songfile+”‘”+ ” -g 100″ #plays the MP3 in it’s entierty. As long as the song is longer than a minute then will only trigger once in the minute that start of the “wake” event

print command
os.system(command) #runs the bash command
else:
print “Comparison:Fail” #the “wake” event’s start time != the system’s current time

def callable_func():
os.system(“clear”) #this is more for my benefit and is in no way necesarry
print “————start———–”
FullTextQuery(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

Credit goes to esologic

November 21st, 2015|Categories: raspberry pi|Tags: , , , , |0 Comments

Leave A Comment