Befehle über Google Kalender

Heute ist Stammtischzeit:
Jeden Donnerstag 20:30 Uhr hier im Chat.
Wer Lust hat, kann sich gerne beteiligen. ;)
  • Hallo Forum,
    ich möchte über den Google Kalender einen Roboter steuern. Ich bin dieser Anleitung gefolgt: http://www.dexterindustries.com/BrickPi/projec…h-raspberry-pi/
    Habe die benötigten Ordner ausgepackt und sie sind auch alle unter /home/pi. Doch wenn ich das Script starte, erscheint nur dies:

    Code
    ------------start-----------
    Full text query for events on Primary Calendar: 'wake1'


    Sollte da nicht noch mehr erscheinen? Das ist mein Script:
    [code=php]#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 logging # used for development. Not needed for normal usage.
    logging.basicConfig(filename='alarm.log', filemode='w')


    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

    import multiprocessing
    from random import randint
    from BrickPi import *
    import subprocess

    #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 = 'email' #your email
    calendar_service.password = 'passwort' #your password
    calendar_service.source = 'Google-Calendar_Python_Sample-1.0'
    calendar_service.ProgrammaticLogin()

    #*****************************************
    #Alarm processing starts
    #To stop the output when playing the alarm
    devnull = open('/dev/null', 'w')

    #Plays the alarm
    def play_alarm(num):
    while(1):
    subprocess.call(["mpg321", "alarm_sound.mp3"],stdout=devnull,stderr=devnull)
    #return

    #Move the bot forward and turns 90 degree if an obstacle is encountered
    #Stops when a touch sensor is pressed on Port 1 or 2
    def wait_inp(num):
    ot = time.time()
    while True:
    #Move Motors
    power = -150
    BrickPi.MotorEnable[PORT_A]=1
    BrickPi.MotorEnable[PORT_D]=1
    BrickPi.MotorSpeed[PORT_A] = power
    BrickPi.MotorSpeed[PORT_D] = power
    BrickPi.MotorSpeed[PORT_A] = power
    BrickPi.MotorSpeed[PORT_D] = power
    result = BrickPiUpdateValues()

    #Get values from both touch sensors and ultrasonic sensor
    b1=BrickPi.Sensor[PORT_1]
    b2=BrickPi.Sensor[PORT_2]
    udist=BrickPi.Sensor[PORT_4]
    #print udist

    #Return to main if any touch sensor is pressed
    if b1 or b2:
    return

    #If the US sensor reads less than 20cm and the new distance value is older by 5secs, rotate 90 degrees
    #(New value checked because while rotating, the US sensor would read less that threshold for a few secs)
    if int(udist)<200 and time.time() - ot > 5:
    ot = time.time()
    power1=[-150,-150]
    deg=[110,-110]
    port=[PORT_A,PORT_D]
    motorRotateDegree(power1,deg,port,.1)
    time.sleep(.1) # sleep for 10 ms

    #Alarm processing ends
    #*****************************************

    def FullTextQuery(calendar_service, text_query='wake1'):
    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 "---"
    while True:
    BrickPiSetup()

    #Set up motors, US sensor and touch sensors
    BrickPi.MotorEnable[PORT_A] = 1 #Enable the Motor A
    BrickPi.MotorEnable[PORT_D] = 1 #Enable the Motor B

    BrickPi.SensorType[PORT_4] = TYPE_SENSOR_ULTRASONIC_CONT
    BrickPi.SensorType[PORT_1] = TYPE_SENSOR_TOUCH #Set the type of sensor at PORT_1
    BrickPi.SensorType[PORT_2] = TYPE_SENSOR_TOUCH

    BrickPiSetupSensors() #Send the properties of sensors to BrickPi

    #Set timeout
    BrickPi.Timeout=1000
    BrickPiSetTimeout()
    BrickPi.Timeout=1000
    BrickPiSetTimeout()

    #Start two parallel processes
    jobs = []

    #Start alarm process
    p1 = multiprocessing.Process(target=play_alarm, args=(0,))
    jobs.append(p1)
    p1.start()

    #Start motor run process
    p3 = multiprocessing.Process(target=wait_inp, args=(1,))
    jobs.append(p3)
    p3.start()

    #The motor run process returns when any button is pressed
    p3.join()
    #Terminate the alarm process when any button press is recieved
    p1.terminate()

    #Button 1: Snooze
    #Button 2: Turn Off alarm
    result = BrickPiUpdateValues()
    b1=BrickPi.Sensor[PORT_1]
    b2=BrickPi.Sensor[PORT_2]
    print b1,b2

    #Kill the alarm that is already running
    p = subprocess.Popen(['pidof', 'mpg321'], stdout=subprocess.PIPE)
    out, err = p.communicate()
    for line in out.split(" "):
    os.kill(int(line), 9)

    #If button 1 is pressed then snooze for 5 minutes
    if b1:
    print "Snooze for 5 mins"
    time.sleep(300)

    #If button 2 is pressed then stop the alarm
    if b2:
    print "exit:"
    return

    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
    [/php]

    Einmal editiert, zuletzt von modulok (6. Juni 2015 um 20:51)

  • [font="monospace"]

    Zitat

    [/font]

    Zitat
    Zitat


    [font="monospace"][font="monospace"]gdata.service.RequestError: {'status': 403, 'body': '<HTML>\n<HEAD>\n<TITLE>Forbidden</TITLE>\n</HEAD>\n<BODY BGCOLOR="#FFFFFF" TEXT="#000000">\n<H1>Forbidden</H1>\n<H2>Error 403</H2>\n</BODY>\n</HTML>\n', 'reason': 'Forbidden'}[/font][/font]
    [font="monospace"]

    [/font]

    [font="monospace"]Da steht's doch: FORBIDDEN[/font]

    [font="monospace"]Ist wohl doch etwas mit dem Login :fies: [/font]

    • Offizieller Beitrag

    Oder das google seit Tutorialerstellung mal wieder was an ihrer API gedreht hat. Hast du ne Mail gekriegt,das sich ein 3. Programm versucht ein einzuloggen bzw. die Sicherheitseinstellungen für 3. Anbieterapps (oder wie immer das heisst) runtergschraubt?

  • Ja, nur was?

    calendar_service.email = 'email' # Hier habe ich meine Google-Mail Adresse eingetragen
    calendar_service.password = 'password' # Und hier mein Google-Passwort.
    calendar_service.source = 'Google-Calendar_Python_Sample-1.0' # Vielleicht stimmt diese Zeile nicht?

    Also mit meiner Mail und dem Passwort kann ich mich bei Google anmelden. Vielleicht wird der Pi ja irgendwie von Google blockiert? Muss ich noch was installieren?

    Einmal editiert, zuletzt von modulok (2. Juni 2015 um 21:23)

  • So ist es richtig, nur die Einrückungen stimmen hier nicht. Habe auch meinen ersten Post editiert.


    Einmal editiert, zuletzt von modulok (2. Juni 2015 um 21:37)


  • ich kann am Montag mal probieren ob das mir klappt, wenn es dir helfen würde.

    Ja, das wäre nett. Es muss irgend etwas schon beim log in nicht stimmen, weil egal was ich bei email oder Passwort eingebe, es kommt die selbe Fehlermeldung. Sind aber meine Google-Daten..

  • Hallo Forum,
    ich versuche nun, mein Projekt mit dem Tool gcalcli umzusetzen, steige aber noch nicht so ganz durch. Ich habe bisher dieses Script (Quelle: https://developers.google.com/google-apps/ca…ickstart/python ), welches auch funktioniert:


    Gebe ich nun

    Code
    sudo gcalcli calm


    ein, wird mir z.B. der Monat in der Kommandozeile angezeigt. Wie schaffe ich es nun, dass das Script bei einem bestimmten Kalendereintrag eine Aktion ausführt?
    Danke schon mal für Hilfe.

    Einmal editiert, zuletzt von modulok (15. Juni 2015 um 20:48)

  • Ja, wenn ich das Script an sich ausführe, habe ich die nächsten 10 Kalendereinträge:

    Code
    pi@raspberrypi ~ $ sudo python quickstart.py
    Getting the upcoming 10 events
    2015-06-15T21:30:00+02:00 wake
    2015-06-16T07:00:00+02:00 wake2
    2015-06-16T09:30:00+02:00 wake3
    2015-06-16T13:00:00+02:00 wake4


    Habe jetzt mal 4 auf die Schnelle eingetragen.

    Einmal editiert, zuletzt von modulok (15. Juni 2015 um 21:43)

    • Offizieller Beitrag

    Auf die schnelle
    [code=php]
    for event in events:
    if event['summary'].Split(" ")(1) == "wake"
    print "hier koennte ich jetzt was sinnvolles machen"[/php]

    Es gibt bestimmt auch nen direkten Weg sich den Betreff zu holen, aber durch die doku kannst du dich quälen ;)

Jetzt mitmachen!

Du hast noch kein Benutzerkonto auf unserer Seite? Registriere dich kostenlos und nimm an unserer Community teil!