Notices


Reply
Thread Tools
Posts: 277 | Thanked: 319 times | Joined on Jan 2010
#501
Originally Posted by Win7Mac View Post
Big thanks slarti!

I couldn't get it to work by simply adding import sys at the top too. So what about the syntax errors?
You wrote the command in shell, not in the python interpreter. If you add import sys to where import dbus is and run the modified script with:
Code:
python myscript.py
it will tell you where the problem is.

Originally Posted by Win7Mac View Post
Yeah! Now I got the picture about the special chars in python. Works great.
Great!

Originally Posted by Win7Mac View Post
Almost done now, just get rid of the 'No alarms' msg in a way that the line in BB disappears (and won't leave a blank line), if there's no alarm. Add the second alarm probably?
Just replace the command that prints the "No alarms" with pass.

I'll have to think about the second alarm. I'm only learning python and scripting myself and this script was meant for just the next one. It sorts the alarms chronologically and prints the next one (from now) in the list. It could print the next two but then this next part would be more difficult:

Originally Posted by Win7Mac View Post
Edit: I'm already using your script for short weekday, could this be implemented in the above script to adopt to my language? I prefer short weekday very much over the "+1" from {events}, good idea!
I added a "translator" to this version and changed the No alarms part to what you wanted. It's in finnish, though, so you'll have to change abb_weekdays to what you want. Just make sure you start from sunday.

Code:
#!/usr/bin/python

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('%H:%M',weekdays[day]),attributes['TITLE']))


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

abb_weekdays = ['Su','Ma','Ti','Ke','To','Pe','La']
next_alarm_list = next_alarm.split(' ' ,1)

print ' '.join((abb_weekdays[int(next_alarm_list[0])],next_alarm_list[1])).encode('utf-8') + '\xe2\x98\x9a'
 

The Following User Says Thank You to slarti For This Useful Post:
Win7Mac's Avatar
Community Council | Posts: 664 | Thanked: 1,648 times | Joined on Apr 2012 @ Hamburg
#502
Originally Posted by coderus View Post
its sh-bang.
Thanks, so it is always required, right?

Originally Posted by slarti View Post
You wrote the command in shell, not in the python interpreter. If you add import sys to where import dbus is and run the modified script with:
Code:
python myscript.py
it will tell you where the problem is.
Ah, ok. Included import sys and it works in terminal and BB now.
So the syntax errors can be ignored?

I'll settle for your edited script if I can't resolve this multi-line fields issue, many thanks for that.

Originally Posted by thp View Post
Yes, {{color}} only goes to the end of the current line for now. What you could do is set the global color to blue, and then prefix every line that you don't want to have in blue with the desired color. At least this works as long as you don't have any other multi-line fields (for scripts, you can modify them to output the color prefix on every line).
That works, with mentioned limitations.
I tried to place {{color}} and add special characters in several places in upcoming_alarms.py without success, where does it belong?

Here's a screenshot, so you get a better idea what I'm trying to achieve:
Attached Images
 
__________________
Nokia 5110 > 3310 > 6230 > N70 > N9 BLACK 64GB
Hildon Foundation Board member
Maemo Community e.V. co-creator, founder and director since Q4/2016
Current Maemo Community Council member
 

The Following User Says Thank You to Win7Mac For This Useful Post:
Posts: 277 | Thanked: 319 times | Joined on Jan 2010
#503
I just realised that the alarm trigger timestamps and cookies ARE in the contextkit. I'll write a much simpler script later today.
 
Posts: 277 | Thanked: 319 times | Joined on Jan 2010
#504
Ok, took a bit longer than I thought but here is the *Ultimate Customizable Alarm Attribute Getter*™

It's a lot more accurate than the ones before because it gets the times directly from the contextkit timestamps so they are always correct and in order. It even shows when an alarm will go off again after pressing snooze.

Just follow the instructions in the comments and print out anything about an alarm or alarms.

Code:
#!/usr/bin/python
# Print various attributes of alarm(s) by modifying the last line
# Author: Slarti

import dbus
from datetime import datetime, timedelta, date

bus = dbus.SystemBus()

time_obj = bus.get_object('com.nokia.time', '/com/nokia/time')
time_intf = dbus.Interface(time_obj, 'com.nokia.time')
alarm_obj = bus.get_object('com.nokia.time', '/org/maemo/contextkit/Alarm/Trigger')
alarms = alarm_obj.Get(dbus_interface='org.maemo.contextkit.Property')[0]
cookies = alarms[0].keys()
alarms_list = []
for cookie in cookies:
        timestamp = alarms[0][cookie]
        attributes = time_intf.query_attributes(cookie)
        alarms_list.append(((timestamp,cookie,attributes)))

alarms_list.sort()

# Change these to your own language in the order
# they are in if you want to print the weekday:

abb_weekdays = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun']

# Choose the limit for the number of alarms (lines) to print:

limit = 5

# Don't touch this:

if len(alarms_list) < limit:
        limit = len(alarms_list)

# This generates what to print on every line:

for i in range(limit):

# Don't touch this:

        alarm_timestamp = datetime.fromtimestamp((alarms_list[i][0])/1000000000)

# You can choose from these:

        weekday = abb_weekdays[date.weekday(alarm_timestamp)]
        title = alarms_list[i][2]['TITLE']
        alarmtime = datetime.strftime(alarm_timestamp,"%H:%M")
        time_to_alarm = ':'.join(str(alarm_timestamp - datetime.now()).split(':')[:2])
        snooze = alarms_list[i][2]['snooze']+'min'

# This is the special character. Look for the Python source code
# string at e.g. http://www.fileformat.info/info/unicode/block/index.htm

        sc = u"\u2691"

# Here you can decide what to print in which order:

        print (weekday+' '+title+' '+alarmtime+' '+time_to_alarm+' '+snooze+' '+sc).encode('utf-8')
 

The Following 9 Users Say Thank You to slarti For This Useful Post:
Win7Mac's Avatar
Community Council | Posts: 664 | Thanked: 1,648 times | Joined on Apr 2012 @ Hamburg
#505
Whow... now we're talking...
Great job, very cool!
I wish we could have this for events.

Only thing left: where to put the {{color}} tag in the script for all alarms?

@thp: a button to update/refresh all info would be nice.
Actually I start/close music player every time...
__________________
Nokia 5110 > 3310 > 6230 > N70 > N9 BLACK 64GB
Hildon Foundation Board member
Maemo Community e.V. co-creator, founder and director since Q4/2016
Current Maemo Community Council member
 
coderus's Avatar
Posts: 6,436 | Thanked: 12,701 times | Joined on Nov 2011 @ Ängelholm, Sweden
#506
look for update script and use it with profilematic
__________________
Telegram | Openrepos | GitHub | Revolut donations
 
Posts: 277 | Thanked: 319 times | Joined on Jan 2010
#507
Originally Posted by Win7Mac View Post
Whow... now we're talking...
Great job, very cool!
I wish we could have this for events.
Thanks.

It's possible to get the cookies for the queued events, too. Might be doable with some changes. What attributes would have to be included?

Originally Posted by Win7Mac View Post
Only thing left: where to put the {{color}} tag in the script for all alarms?
Anywhere on the last line. You just have to surround it with quotes. If you want the whole line(s) to be green, put it in the front.

Example:

Code:
print ('{{green}}'+weekday+' '+title+' '+alarmtime+' '+time_to_alarm+' '+snooze+' '+sc).encode('utf-8')
 

The Following User Says Thank You to slarti For This Useful Post:
Win7Mac's Avatar
Community Council | Posts: 664 | Thanked: 1,648 times | Joined on Apr 2012 @ Hamburg
#508
Originally Posted by coderus View Post
look for update script and use it with profilematic
OK, so I found this and ran in terminal:
Code:
text=$(gconftool -g /apps/billboard/text)
gconftool -s -t string /apps/billboard/text "{{white}}Updating..."
gconftool -s -t string /apps/billboard/text "${text}"
and now my LPS shows "Updating..." - not so great!
The text in BB is still there, but it's not showing anymore.
I also tried without the middle line, but it remains telling me "Updating..."
Could you please provide a fix and the correct code for terminal too?

Originally Posted by slarti View Post
It's possible to get the cookies for the queued events, too. Might be doable with some changes. What attributes would have to be included?
Just the way you have it put in the *Ultimate Customizable Alarm Attribute Getter*™...

Originally Posted by slarti View Post
Anywhere on the last line. You just have to surround it with quotes. If you want the whole line(s) to be green, put it in the front.
Ah, I didn't know about the additional quotes.
Too bad actually I can't test it, because of the above issue...
__________________
Nokia 5110 > 3310 > 6230 > N70 > N9 BLACK 64GB
Hildon Foundation Board member
Maemo Community e.V. co-creator, founder and director since Q4/2016
Current Maemo Community Council member
 
Posts: 277 | Thanked: 319 times | Joined on Jan 2010
#509
Originally Posted by Win7Mac View Post
The text in BB is still there, but it's not showing anymore.
I also tried without the middle line, but it remains telling me "Updating..."
Could you please provide a fix and the correct code for terminal too?
If you haven't fixed this already and billboard still shows you your own text in the app (which I doubt), copy it all and in terminal write:

Code:
gconftool -s -t string /apps/billboard/text "PASTE YOUR TEXT HERE"
Coderus' script takes the gconf value that gets written by Billboard and stores it in the variable $text. Then it replaces that value in gconf with "Updating..." and immediately after that it writes over that with the original text. This forces an update in Billboard. It works like a charm but probably the last command didn't get executed when you tried it in terminal. It should be used as a script so that all commands get executed.

As your original text is probably lost, you'll just have to write it again...
 

The Following User Says Thank You to slarti For This Useful Post:
Win7Mac's Avatar
Community Council | Posts: 664 | Thanked: 1,648 times | Joined on Apr 2012 @ Hamburg
#510
BIG BIG THANKS SLARTI!
Works again, text was still there in BB. I started editing in there and whoops, it came back...
And after disabling and reenabling other logo and meecast appearence settings, the meecast logo came back too...

So, for use in terminal is this script usable or does it have to be modified?
Anyway, a button in BB would be way more comfortable, not only for Linux-noobs like me...

slarti, your script works great, I love it!
__________________
Nokia 5110 > 3310 > 6230 > N70 > N9 BLACK 64GB
Hildon Foundation Board member
Maemo Community e.V. co-creator, founder and director since Q4/2016
Current Maemo Community Council member
 
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 18:34.