aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Scheibenpflug <zorchenhimer@gmail.com>2015-04-01 03:49:59 (GMT)
committerNick Scheibenpflug <zorchenhimer@gmail.com>2015-04-01 03:49:59 (GMT)
commit5a020434f1a778e48eacd935deb231610c37af85 (patch)
treebe9482081da66d07e325ce05104fdc0a7df99c3c
downloadslipshine-rss-5a020434f1a778e48eacd935deb231610c37af85.zip
slipshine-rss-5a020434f1a778e48eacd935deb231610c37af85.tar.gz
Initial commit.
-rw-r--r--.gitignore1
-rw-r--r--rss-fix.pl34
-rw-r--r--rss-fix_no-xml-rss.pl69
3 files changed, 104 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..1377554
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
*.swp
diff --git a/rss-fix.pl b/rss-fix.pl
new file mode 100644
index 0000000..54ff1f2
--- /dev/null
+++ b/rss-fix.pl
@@ -0,0 +1,34 @@
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use XML::RSS;
7use LWP::Simple;
8use Digest::MD5 qw(md5_hex);
9
10my $rss = new XML::RSS;
11my $borked_rss = get('http://orgymania.net/updates.xml');
12my $data = $rss->parse($borked_rss);
13
14foreach my $item (@{$data->{'items'}}) {
15 my $orig_title = $item->{'title'};
16 $item->{'description'} =~ /<a href="([^"]+)">([^<]+)<\/a>/;
17 my ($real_link, $real_title) = ($1, $2);
18
19 $item->{'description'} =~ s/<.*?>//g;
20 $item->{'description'} =~ s/\s+/ /sg;
21
22 $item->{'description'} =~ s/^ //g;
23 $item->{'description'} =~ s/ $//g;
24
25 $item->{'link'} = $real_link;
26 $item->{'title'} = $real_title;
27 $item->{'guid'} = md5_hex("$orig_title $real_link");
28}
29
30$data->save('fixed.xml');
31
32print "Content-type: text/xml\n\n";
33print $data->as_string;
34
diff --git a/rss-fix_no-xml-rss.pl b/rss-fix_no-xml-rss.pl
new file mode 100644
index 0000000..0285812
--- /dev/null
+++ b/rss-fix_no-xml-rss.pl
@@ -0,0 +1,69 @@
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Digest::MD5 qw(md5_hex);
7use LWP::Simple;
8
9my $borked_rss = get('http://orgymania.net/updates.xml');
10$borked_rss =~ /<channel>(.*?)<item>/s;
11my $header = $1;
12my %header_sections = $header =~ /<([^>]+)>(.*?)<\/\1>/smg;
13
14$header_sections{'docs'} = '';
15$header_sections{'generator'} = 'Not Slipshine. That shit\'s borked.';
16
17my @items = $borked_rss =~ /<item>(.*?)<\/item>/smg;
18
19my @new_items;
20
21foreach my $item (@items) {
22 my %sections = $item =~ /<([^>]+)>(.*?)<\/\1>/smg;
23
24 $sections{'description'} =~ s/^\s+//sg;
25 $sections{'description'} =~ s/\s+/ /sg;
26 $sections{'description'} =~ s/<!\[CDATA\[//sg;
27 $sections{'description'} =~ s/\s*\]\]>//sg;
28
29 $sections{'description'} =~ /href="([^"]+)"/;
30 my $real_link = $1;
31
32 $sections{'description'} =~ s/<br> /\n/g;
33 $sections{'description'} =~ s/<[^>]+>//g;
34 $sections{'description'} =~ s/\n/ - /sg;
35 $sections{'description'} =~ s/\s+$//sg;
36
37 $sections{'description'} =~ /^(.+) by (.+) - (.+)$/;
38 my $real_title = $1. ' - '. $3;
39
40 ## Re-assignment
41 $sections{'link'} = $real_link;
42 $sections{'title'} = $real_title;
43 $sections{'guid'} = md5_hex($real_title.$real_link);
44 $sections{'description'} .= "<br /><a href=\"$real_link\">$real_link</a>";
45 push(@new_items, \%sections);
46}
47print "Content-type: text/xml\n\n";
48
49print qq(<?xml version="1.0" encoding="iso-8859-1" ?>\n<rss version="2.0">\n);
50print "<channel>\n\t<title>$header_sections{title}</title>\n",
51 "\t<description>$header_sections{description}</description>\n",
52 "\t<pubDate>$header_sections{pubDate}</pubDate>\n",
53 "\t<generator>$header_sections{generator}</generator>\n",
54 "\t<link>$header_sections{link}</link>\n";
55
56foreach my $n_item (@new_items) {
57 print "\t<item>\n";
58 foreach my $section (sort keys %{$n_item}) {
59 if( $section eq 'description' ) {
60 print "\t\t<description><![CDATA[$n_item->{description}]]></description>\n";
61 } elsif( $section eq 'guid' ) {
62 print "\t\t<guid isPermaLink=\"false\">$n_item->{guid}</guid>\n";
63 } else {
64 print "\t\t<$section>$n_item->{$section}</$section>\n";
65 }
66 }
67 print "\t</item>\n";
68}
69print "</channel>\n</rss>\n";