User talk:Bucz: Difference between revisions
Line 30: | Line 30: | ||
:Put only the parts that involve code, the <> parts, in the tags.{{User:Lelouch/sig}} 22:33, 15 September 2009 (BST) | :Put only the parts that involve code, the <> parts, in the tags.{{User:Lelouch/sig}} 22:33, 15 September 2009 (BST) | ||
<pre> | |||
#!/usr/bin/perl | |||
use warnings; | |||
use strict; | |||
#.......url with the weather | |||
my $num = $ARGV[0] || 878; # code for Providence | |||
my $pageurl = 'http://www.timeanddate.com/worldclock/city.html?n='.$num; | |||
#.......filter to get the decription | |||
my $filter_description = '<tr><td>Description:</td><td colspan="3">(.*?)</td></tr>'; | |||
my $www = page($pageurl); | |||
$www =~ /$filter_description/; | |||
my $desc = $1; | |||
#.......some error, no descripton found | |||
if (not $desc) { | |||
print STDERR "no description!\n"; | |||
exit; | |||
} | |||
# my $desc = 'Foggy. Showers.'; | |||
fogcheck($desc); | |||
printf "%s #\n%s\n", $desc, description($desc); | |||
exit; | |||
#................................................................ | |||
#.......process description | |||
# split the sentences and and merge again into something more accurate. | |||
sub description { | |||
my $desc = shift || return; | |||
#.......trim sentence | |||
$desc =~ s/^\s+//g; | |||
$desc =~ s/[\s\.]+$//g; | |||
#.......split sentences | |||
my @a = split /\s*\.\s*/, $desc; | |||
return '' if not @a; #.......empty? | |||
return sprintf "%s.", $a[0] if scalar @a == 1; #.......only one sentence | |||
#.......if there are two, merge them into a single one | |||
return sprintf "%s, %s.", $a[0], lc $a[$#a] if scalar @a == 2; | |||
#.......if there are tree or more, merge first two and the last one | |||
return sprintf "%s, %s. %s.", $a[0], lc $a[1], $a[$#a]; | |||
} | |||
#................................................................ | |||
sub fogcheck { | |||
my $desc = shift; | |||
fogalarm() if $desc =~ /\bFOG/i; | |||
} | |||
#................................................................ | |||
#.......................ADJUST THOSE, IF NEEDED.................. | |||
#................................................................ | |||
#.......get source of the webpage | |||
sub page { | |||
my $url = shift || return; | |||
#........quiet, timeout 30 sec, output to stdout | |||
return `wget -q -t 30 -O - '$url'`; | |||
} | |||
#................................................................ | |||
#.......here, react for fog. write a flag to a file, or something | |||
sub fogalarm { | |||
print "FOG!\n"; | |||
} | |||
</pre> |
Revision as of 12:49, 17 September 2009
Welcome to the Wiki!
Feel free to stop by my talk page if you have any further questions. As for signing your posts/edits, use four tildes (~~~~) or just hit the signature button at the top of the editing window. --Bob Boberton TF / DW 22:32, 9 September 2009 (BST)
What the hell?
Why did you delete my signature, as seen here?--Yonnua Koponen Talk ! Contribs 15:57, 10 September 2009 (BST)
- I'm going to pipe in and suggest that it was a mistake, it happens from time to time. --DANCEDANCEREVOLUTION-- 16:07, 10 September 2009 (BST)
- Yeah, I tend to do annoyed titles though. I'd still like to know why he did it. Then we can prevent the same mistake again.--Yonnua Koponen Talk ! Contribs 16:09, 10 September 2009 (BST)
- Me? No idea. My mistake, eventually. Or maybe some zombies, though. -- Bucz 00:54, 11 September 2009 (BST)
- Yeah, I tend to do annoyed titles though. I'd still like to know why he did it. Then we can prevent the same mistake again.--Yonnua Koponen Talk ! Contribs 16:09, 10 September 2009 (BST)
http://wiki.urbandead.com/index.php/User_talk:Brainguard#weather_script
Your Script
If you have a weather-detection script, you may be able to do something a lot more useful than submitting suggestions; if you make a UD-based greasemonkey script with your weather reader, people will actually have a good chance of seeing it implemented. Lelouch vi Britannia is helping make Ridleybank green_ and gives Achievements 18:57, 10 September 2009 (BST)
- Why greasemonkey? I don't know much about JavaScript. The script I have made is in Perl, like the engine (I suppose), so it would be easy to integrate. -- Bucz 10:47, 11 September 2009 (BST)
- Because Greasemonkey alters Client Side Scripting, allowing users to implement your changes without kevin or Urban Dead having to do a thing. If you have another plugin that accomplishes the same thing, feel free to use that one, but less than .001% of all suggestions are implemented whether they pass or not... Lelouch vi Britannia is helping make Ridleybank green_ and gives Achievements 13:35, 11 September 2009 (BST)
No Wiki Tags
You need to place it in no wiki tags, a button can be found in your tool panel, the crossed red circle with a 'W' in it, or use the raw tags: <nowiki></nowiki>
Ironically, to display the tags I had to put them in no wiki tags.... -- .
. <== DDR Approved Editor 23:09, 14 September 2009 (BST)
Thanks, but now when I paste the script new lines are not respected - puts all in a single veeery long wrapped (crapped) line... -- Bucz 20:05, 15 September 2009 (BST)
- Put only the parts that involve code, the <> parts, in the tags. Lelouch vi Britannia is helping make Ridleybank green_ and gives Achievements 22:33, 15 September 2009 (BST)
#!/usr/bin/perl use warnings; use strict; #.......url with the weather my $num = $ARGV[0] || 878; # code for Providence my $pageurl = 'http://www.timeanddate.com/worldclock/city.html?n='.$num; #.......filter to get the decription my $filter_description = '<tr><td>Description:</td><td colspan="3">(.*?)</td></tr>'; my $www = page($pageurl); $www =~ /$filter_description/; my $desc = $1; #.......some error, no descripton found if (not $desc) { print STDERR "no description!\n"; exit; } # my $desc = 'Foggy. Showers.'; fogcheck($desc); printf "%s #\n%s\n", $desc, description($desc); exit; #................................................................ #.......process description # split the sentences and and merge again into something more accurate. sub description { my $desc = shift || return; #.......trim sentence $desc =~ s/^\s+//g; $desc =~ s/[\s\.]+$//g; #.......split sentences my @a = split /\s*\.\s*/, $desc; return '' if not @a; #.......empty? return sprintf "%s.", $a[0] if scalar @a == 1; #.......only one sentence #.......if there are two, merge them into a single one return sprintf "%s, %s.", $a[0], lc $a[$#a] if scalar @a == 2; #.......if there are tree or more, merge first two and the last one return sprintf "%s, %s. %s.", $a[0], lc $a[1], $a[$#a]; } #................................................................ sub fogcheck { my $desc = shift; fogalarm() if $desc =~ /\bFOG/i; } #................................................................ #.......................ADJUST THOSE, IF NEEDED.................. #................................................................ #.......get source of the webpage sub page { my $url = shift || return; #........quiet, timeout 30 sec, output to stdout return `wget -q -t 30 -O - '$url'`; } #................................................................ #.......here, react for fog. write a flag to a file, or something sub fogalarm { print "FOG!\n"; }