Use a Raspberry Pi and Google Calander to set an alarm

Use Google Calendar to set an alarm on the Raspberry Pi.

http://raspberrypi-hacks.com/45/smart-alarm-clock-with-google-calendar-and-raspberry-pi/

 

 

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

 

Issues with soldering – I recomend Multicore Savbit Alloy Solder

Multicore Alloy SolderI recently purchased Maplins leadfree solder and had lots of issues with it.  I thought it might have something to do with the soldering iron not getting hot enough so bought a new Antex iron.  The old one was over 20 years old.

Unfortunatly the bit on the new iron became very black very quickly and again refused to melt the solder, so I bought new tips for the iron.

After doing some research I found other similar complaints about Maplins own brand solder, so ordered up some Multicore Savbit Aloy Solder from ebay.

What a difference it makes.  It melts quickly and flows easilly.

Vintage Ersin Multicore Solder Alloy Sn63 Tin Lead 63 37 nos free shipping 1 2lb
Vintage Ersin Multicore Solder Alloy Sn63 Tin Lead 63 37 nos free shipping 1 2lb $29.99
End Date: Sunday May-21-2017 18:37:44 PDT
Buy It Now for only: $29.99
ERSIN MULTICORE SOLDER Alloy 115 470 18SWG 12mm 048 1 LB
ERSIN MULTICORE SOLDER Alloy 115 470 18SWG 12mm 048 1 LB $15.00
End Date: Friday May-19-2017 13:32:19 PDT
Buy It Now for only: $15.00
ERSIN MULTICORE SOLDER Alloy 115 470 18SWG 12mm 048 1 LB New Old Stock
ERSIN MULTICORE SOLDER Alloy 115 470 18SWG 12mm 048 1 LB New Old Stock $20.00
End Date: Friday May-19-2017 8:45:23 PDT
Buy It Now for only: $20.00
ERSIN MULTICORE SOLDER Alloy 235 471 18SWG 12mm 048 1 LB New Old Stock
ERSIN MULTICORE SOLDER Alloy 235 471 18SWG 12mm 048 1 LB New Old Stock $15.00
End Date: Friday May-19-2017 8:33:05 PDT
Buy It Now for only: $15.00
ERSIN MULTICORE SAVBIT ALLOY 5 CORE SOLDER 126oz ENGLAND
ERSIN MULTICORE SAVBIT ALLOY 5 CORE SOLDER 126oz ENGLAND $21.95
End Date: Saturday Apr-29-2017 7:20:31 PDT
Buy It Now for only: $21.95
Size 5 Multicore Tube Savbit Alloy Electrical Solder
Size 5 Multicore Tube Savbit Alloy Electrical Solder $20.32
End Date: Saturday May-13-2017 23:20:11 PDT
Buy It Now for only: $20.32
5 Tubes Savit Alloy Ersin Multicore Electrical Solder
5 Tubes Savit Alloy Ersin Multicore Electrical Solder $55.00
End Date: Wednesday May-17-2017 8:15:07 PDT
Buy It Now for only: $55.00
Multicore Size 5 Tube Savbit Alloy Solder
Multicore Size 5 Tube Savbit Alloy Solder $25.03
End Date: Monday May-8-2017 4:18:57 PDT
Buy It Now for only: $25.03
Multicore Size 10 Reel Alloy Solder 07mm Diameter 110g
Multicore Size 10 Reel Alloy Solder 07mm Diameter 110g $38.22
End Date: Tuesday May-9-2017 6:51:05 PDT
Buy It Now for only: $38.22
Old car tool 5 core savbit alloy ersin multicore solder size 5 made Hemel London
Old car tool 5 core savbit alloy ersin multicore solder size 5 made Hemel London $9.20
End Date: Friday Apr-28-2017 8:39:58 PDT

« Previous12

My Current Pi Projects

Featured

Update 16 July 2016

Raspberry Pi's

Used waiting new use - 1 x Pi2, 1 x B+, 2 x B, 2 x A+, 3 x A
New Raspberry Pi - Zero (1.2), Zero (1.3), B+
Broken - 1 x B+ (water), 2 x B rev 2 (ebay arrived O/S)
Missing - 1 x B rev 1

TinyTX3 - Wireless Sensors - http://nathan.chantrell.net/tinytx-wireless-sensor/

  • Bathroom - DHT22 Humidity Sensor (Node 11)
  • Kitchen - DHT22 Humidity Sensor (12)
  • Hallway - DHT22 Humidity Sensor (14)
  • Extractor Fan Pipe - DHT22 Humidity Sensor (15)
  • Freezer- DS18B20 1-Wire Temperature Sensor (23)
  • Fridge - DS18B20 1-Wire Temperature Sensor (24)
  • Spare - DS18B20 1-Wire Temperature Sensor (26)
  • PC Case - DS18B20 1-Wire Temperature Sensor (27)
  • Air Con Fan - dual DS18B20 1-Wire Temperature Probes (29)
  • Door Switch (5)
  • Window Switch (6)

 

This site is a collection of notes, documentation and web links for my Pi's.

Retired Pi Uses

I mainly buy parts from CPC, ModMyPi, Pimoroni and eBay