{"id":1750,"date":"2006-08-05T09:36:00","date_gmt":"2006-08-05T16:36:00","guid":{"rendered":"http:\/\/www.sheer.us\/wordpress\/?p=1750"},"modified":"2006-08-05T09:36:00","modified_gmt":"2006-08-05T16:36:00","slug":"as-is-so-often-the-case","status":"publish","type":"post","link":"http:\/\/www.sheer.us\/weblogs\/uncategorized\/as-is-so-often-the-case","title":{"rendered":"As is so often the case.."},"content":{"rendered":"<p>Sheer has a bit of not-very-well-written code to share. Because nothing immediately jumped out at me for fetching LJ, here is a perl script that will fetch the latest LJ entry from the RSS feed, compare it with a database. You can also find this data in Sheer&#8217;s newly created code directory, where he will share all open source code snippits in the future: http:\/\/www.sheer.us\/code<\/p>\n<p><lj-CUT TEXT=\"lj fetcher\"><\/p>\n<p>#!\/usr\/bin\/perl<\/p>\n<p>use DBI;<br \/>\nuse Data::Dumper;<br \/>\nuse LWP::Simple;<br \/>\nuse XML::Simple;<\/p>\n<p>my $dbh = DBI->connect(&#8220;dbi:mysql:db=obfuscated&#8221;,&#8221;because i&#8221;,&#8221;dont want you accessing it&#8221;);<\/p>\n<p>fetchdata();<\/p>\n<p># yes, this could be a *lot* better<\/p>\n<p>sub fetchdata()<br \/>\n{<br \/>\n        my $xml = XML::Simple->new();<br \/>\n        my $webpage = &#8220;<foo><\/foo>&#8220;;<br \/>\n        $webpage = get(&#8220;http:\/\/sheer-panic.livejournal.com\/data\/rss&#8221;);<\/p>\n<p>        #print $webpage;<\/p>\n<p>        $debug = 0;<\/p>\n<p>        if(! defined $webpage) {<br \/>\n#               die &#8220;sheer sucks&#8221;;<br \/>\n                return 0;<br \/>\n        }<\/p>\n<p>        my $doc = $xml->XMLin($webpage);<\/p>\n<p>#       return($doc->{GRPVOL}{PRV});<\/p>\n<p>        $item = $doc->{channel}{item}[0];<\/p>\n<p>#       print Dumper($item);<br \/>\n#       print Dumper($doc);<\/p>\n<p>        $title = $item->{&#8216;title&#8217;};<br \/>\n        $titleq = $dbh->quote($title);<br \/>\n        $link = $item->{&#8216;link&#8217;};<br \/>\n        $linkq = $dbh->quote($link);<br \/>\n        $guid = $item->{&#8216;guid&#8217;}{&#8216;content&#8217;};<br \/>\n        $guidq = $dbh->quote($guid);<br \/>\n        $text = $item->{&#8216;description&#8217;};<br \/>\n        $textq = $dbh->quote($text);<br \/>\n        $date = $item->{&#8216;pubDate&#8217;};<br \/>\n        $dateq = $dbh->quote($date);<\/p>\n<p>        $sth = $dbh->prepare(&#8220;SELECT lj_seq FROM lj WHERE link = &#8216;$link'&#8221;);<br \/>\n        $sth->execute();<\/p>\n<p>        ($seq) = $sth->fetchrow_array();<\/p>\n<p>        if($seq) {<br \/>\n                print &#8220;we got it&#8221; if ($debug);<br \/>\n                return;<br \/>\n        } else {<br \/>\n                print &#8220;Title: [$title]\\nlink: [$link]\\nGuid:[$guid]\\ntext:[$text]\\ndate:[$date]\\n&#8221; if ($debug);<\/p>\n<p>                $query = &#8220;INSERT INTO lj VALUES (NULL,$linkq,$textq,$titleq,$dateq,$guidq,NOW())&#8221;;<br \/>\n                print &#8220;query: $query\\n&#8221; if ($debug);<br \/>\n                $dbh->do($query);<\/p>\n<p>        }<\/p>\n<p>}<\/p>\n<p>#&#8211;<br \/>\n#&#8211; Table structure for table &#8216;lj&#8217;<br \/>\n#&#8211;<\/p>\n<p>#CREATE TABLE lj (<br \/>\n#  lj_seq int(11) NOT NULL auto_increment,<br \/>\n#  link text,<br \/>\n#  description text,<br \/>\n#  title text,<br \/>\n#  `date` varchar(255) default NULL,<br \/>\n#  guid text,<br \/>\n#  t timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,<br \/>\n#  PRIMARY KEY  (lj_seq)<br \/>\n#) ENGINE=MyISAM DEFAULT CHARSET=latin1;<br \/>\n                                                       <\n<\/lj-CUT><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sheer has a bit of not-very-well-written code to share. Because nothing immediately jumped out at me for fetching LJ, here is a perl script that will fetch the latest LJ entry from the RSS feed, compare it with a database. You can also find this data in Sheer&#8217;s newly created code directory, where he will [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/posts\/1750"}],"collection":[{"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/comments?post=1750"}],"version-history":[{"count":0,"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/posts\/1750\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/media?parent=1750"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/categories?post=1750"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/tags?post=1750"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}