Active Topics

 



Notices


Reply
Thread Tools
coderus's Avatar
Posts: 6,436 | Thanked: 12,701 times | Joined on Nov 2011 @ Ängelholm, Sweden
#561
Originally Posted by thedead1440 View Post
coderus,

Your script has the same fallacy from the looks of it whereby anything below 10% is not shown properly for example 3% becomes 0.3 i.e. 30% bar while thp's method accounts for single integers and 100% too...
i'm talking about your coding style
__________________
Telegram | Openrepos | GitHub | Revolut donations
 
Moderator | Posts: 6,215 | Thanked: 6,400 times | Joined on Nov 2011
#562
Originally Posted by coderus View Post
i'm talking about your coding style
I don't code

Yeah the bar can be added to end of script too; makes no huge issue; you were not specific what "beaty" you wanted to see hence I told you about the fallacy I saw
 
Moderator | Posts: 6,215 | Thanked: 6,400 times | Joined on Nov 2011
#563
Originally Posted by Win7Mac View Post
True, works without -n too.

Also I'm using this script to show uptime in decimal numbers:
Code:
#!/usr/bin/python
# Show Device Uptime in decimal days

sc = u"\u2622"
seconds = int(float(open('/proc/uptime').read().split()[0]))
print 'up: '+("%.1f" % (float(seconds)/float(60*60*24))).replace('.', ',')+' d'+' '+sc.encode('utf-8')
Now I want it to show the after decimal point only when upime is <10 days.
So that it would print "9,9 days" and "10 days".
Could someone put that rule to the script please?
I haven't learned python yet but a fast-and-dirty similar sh script:

Code:
#!/bin/sh
#uptime

days=$(cat /proc/uptime | awk '{print $1}')
days2=`dc $days 86400 / p | cut -c1-4`
days3=`dc $days 86400 / p | awk -F"." '{print $1}'`

if [ $days3 -lt 10 ]
then
echo -n -e up\: $days2 
else 
echo -n -e up\: $days3
fi
echo -n -e \ "\xe2\x98\xA2"
It requires dc to work but IIRC dc is by default present...

dc from Harmattan SDK or here...

Last edited by thedead1440; 2013-01-27 at 16:18.
 

The Following User Says Thank You to thedead1440 For This Useful Post:
EmaNymton's Avatar
Posts: 141 | Thanked: 267 times | Joined on May 2010 @ Germany
#564
And the python version

Code:
#!/usr/bin/python
# Show Device Uptime in decimal days

sc = u"\u2622"
seconds = int(float(open('/proc/uptime').read().split()[0]))
days = float(seconds)/float(60*60*24)
days = "{0:.0f}".format(days) if seconds >= 864000 else "{0:.1f}".format(days)
output = " ".join(['up:',days.replace('.', ','),'d',sc.encode('utf-8')])
print output

Last edited by EmaNymton; 2013-01-27 at 15:30.
 

The Following 2 Users Say Thank You to EmaNymton For This Useful Post:
Moderator | Posts: 6,215 | Thanked: 6,400 times | Joined on Nov 2011
#565
EmaNymton,

I tried your script and got:

Code:
Traceback (most recent call last):
  File "/home/user/uptime2.py", line 7, in <module>
    days = "{:.0f}".format(days) if seconds >= 86400 else "{:.1f}".format(days)
ValueError: zero length field name in format
Is it due to the python version required?

Last edited by thedead1440; 2013-01-27 at 15:24.
 
EmaNymton's Avatar
Posts: 141 | Thanked: 267 times | Joined on May 2010 @ Germany
#566
I think so, tested on desktop pc with python 2.7.

Now it should work
 

The Following 2 Users Say Thank You to EmaNymton For This Useful Post:
Win7Mac's Avatar
Community Council | Posts: 664 | Thanked: 1,648 times | Joined on Apr 2012 @ Hamburg
#567
Originally Posted by thedead1440 View Post
Code:
#!/bin/sh
#uptime

days=$(cat /proc/uptime | awk '{print $1}')
days2=`dc $days 86400 / p | cut -c1-4`
days3=`dc $days 86400 / p | awk -F"." '{print $1}'`

if [ $days3 -lt 10 ]
then
echo -n -e up\: $days2 
else 
echo -n -e up\: $days3
fi
echo -n -e  "\xe2\x98\xA2"
It requires dc to work but IIRC dc is by default present...
Yes, it requires dc which is not preinstalled.
Can't install it now, because "Recource temporarily unavailable".

But the python version works right out of the box.
Thank you guys!
__________________
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
 
Moderator | Posts: 6,215 | Thanked: 6,400 times | Joined on Nov 2011
#568
Originally Posted by Win7Mac View Post
Yes, it requires dc which is not preinstalled.
Could you check if you have libstdc++6? you can also do dpkg -l | grep dc which should show it up... Just curious to know if this is the package which contains it
 
Win7Mac's Avatar
Community Council | Posts: 664 | Thanked: 1,648 times | Joined on Apr 2012 @ Hamburg
#569
Code:
RM696-21-3_PR_001:~# dpkg -l | grep dc
ii  libstdc++6         4.4.1-0maemo14+0m6
The GNU Standard C++ Library v3
__________________
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
 
Moderator | Posts: 6,215 | Thanked: 6,400 times | Joined on Nov 2011
#570
Originally Posted by Win7Mac View Post
Code:
RM696-21-3_PR_001:~# dpkg -l | grep dc
ii  libstdc++6         4.4.1-0maemo14+0m6
The GNU Standard C++ Library v3
And doing dc --help outputs nothing?
 
Reply


 
Forum Jump


All times are GMT. The time now is 23:19.