View Single Post
Posts: 277 | Thanked: 319 times | Joined on Jan 2010
#498
Originally Posted by Win7Mac View Post
What's that exactly? - I only installed python an python-dbus.


Could you paste your code in the script, so it's placed correct and post here?
If you want to use the sys module then you have to import it just like you import other modules. Simply write import sys at the top.

I'm having trouble making thp's script behave nicely because of the generator object from which he prints the alarms. If you can settle for just the next alarm, here is my script added with a special character at the end of the line. If you want it explained or modified, just ask.

Code:
#!/usr/bin/python
# List upcoming alarms on MeeGo 1.2 Harmattan
# Thanks to slarti on TMO for figuring out the D-Bus methods
# Thomas Perl <thp.io/about>; 2012-06-13
# Horribly mangled by slarti to find only the next alarm
# (set from clock application); 2012-06-19
# from http://talk.maemo.org/showpost.php?p=1224180&postcount=107

import dbus
from datetime import datetime, timedelta
import time

bus = dbus.SystemBus()

time_obj = bus.get_object('com.nokia.time', '/com/nokia/time')
time_intf = dbus.Interface(time_obj, 'com.nokia.time')

cookies = time_intf.get_cookies_by_attributes({'enabled': '1'})
today = datetime.now()
tomorrow = today + timedelta(days=1)

def list_queued_alarms():
    for cookie in cookies:
        attributes = time_intf.query_attributes(cookie)
        alarmtime = attributes['alarmtime']
        if attributes['STATE'] == 'QUEUED':
            if 'recurrence' in attributes:
                days = tuple(attributes['recurrence'])
            else:
                if datetime.time(datetime.strptime(alarmtime, ("%H:%M"))) > datetime.time(datetime.now()):
                    days = time.strftime("%w")
                else:
                    days = tomorrow.strftime("%w")
            weekdays = dict([(day, time.strptime((day + " " + alarmtime),'%w %H:%M' )) for day in days])
            for day in days:
                yield ' '.join((day,time.strftime('%a %H:%M',weekdays[day]),attributes['TITLE']))


findme_list = [' '.join((time.strftime('%w %a %H:%M'),'findme'))]
L = list(list_queued_alarms()) + findme_list
L.sort()
findme_string = ' '.join((time.strftime('%w %a %H:%M'),'findme'))
findme_int = L.index(findme_string)
if len(L) == 1:
    next_alarm = 'xxNo alarms'
else:
    if findme_int == (len(L) - 1):
        next_alarm = L[0]
    else:
        next_alarm = L[findme_int + 1]

print next_alarm[2:].encode('utf-8') + '\xe2\x98\x9a'
 

The Following User Says Thank You to slarti For This Useful Post: