You are not logged in.
Hi, i made a small script that is outputting text to my conky, used like this:
${execi 3600 ~/scripts/horoscope.pl scorpio}The problem is that the text doesn't seem to be formatted (it goes off the edge of the conky).
How can i get the output text to "fit" within my conky's width and not go off the screen?
Here is the script:
#!/usr/bin/env perl
use strict;
use warnings;
use LWP::Simple;
my $sign = $ARGV[0];
my @signs = qw(
aries taurus gemini cancer leo virgo
libra scorpio sagittarius capricorn
aquarius pisces
);
sub horoscope($)
{
our $data = get(
'http://my.horoscope.com/astrology/free-daily-horoscope-' . $sign. '.html'
);
if ($data =~ m/(.+)\ id=\"textline\">(.+)<\/div>(.+)/)
{
our $msg = $2 ."\n";
return $msg;
} else
{
return "Error retrieving horoscope.";
}
}
package main;
for my $val (@signs)
{
if ($sign eq $val)
{
print horoscope($val)
}
}Offline
If you are good enough to code a perl script - you are good enough to look in he documentation.
http://perldoc.perl.org/Text/Wrap.html
You will have to do the textwrap in the perl script due to the way conky handles external scriptlets - AFAIK ![]()
Last edited by satanselbow (2012-07-13 10:56:18)
Offline
That won't work, as i change conky often. I _don't want_ a script outputting "hard-formatted" text that will only fit one kind of conky unfortunately.
If that was what i wanted to do i would have done it that way already...
PS; i don't need to be told to read documentation. I wouldn't have bothered posting if i hadn't looked beforehand. It's rather annoying when you spend several hours searching through doc's, misc forums and tutorials trying to find a solution and when you post a thread about it someone asks you to RTFM.....
Offline
I've agonised over the same problem in the past (usually bash rather than perl, but the principle remains the same), and I finally succumed to hard coded formatting in the script. I simply couldn't find a different way to do it.
I suppose, depending on your different conkys, you could pipe the perl script through sed (possibly in a bash script) which would mean that you would only have to change a simple bash script to change the formatting.
Ryzen 5900X 12 core/24 thread - RTX 3090 FE 24 Gb, Asus B550-F Gaming MB, 128Gb Corsair DDR4, Fractal Design Define 7 XL, 5 HD (2 NvME PCI, 4SSD) + 1 x optical.
Linux user #545703
/ is the root of all problems.
Offline