Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
use strict; use warnings; use PerlMonksTickers; use Getopt::Long; use Time::Local; $|++; # as an optimization, we can avoid looking for replies to nodes # we posted more than a certain number of days ago. # to inhibit this, set to 0 or undef. my $ignore_my_posts_older_than_days; my $window_in_hours = 1; my $user; sub usage { die <<EOF; @{_}Usage: $0 --user USERNAME [--ignore DAYS] [--window HOURS] --ignore says to not look for replies to nodes I posted more than that many days ago. Default is no limit. --window says to report only nodes that have been posted within the past so many hours. Default is 1. EOF } GetOptions( 'user=s' => \$user, 'window=i' => \$window_in_hours, 'ignore|old=i' => \$ignore_my_posts_older_than_days, ) or usage; defined $user or usage "--user argument is required.\n"; my $timestamp_of_my_earliest_post = ''; my @root_nodes_of_interest = do { my $ar = PerlMonksTickers->user_nodes( foruser => $user ); @$ar }; if ( $ignore_my_posts_older_than_days ) { $timestamp_of_my_earliest_post = timestamp_of_hours_ago( $ignore_my_posts_older_than_days * 24 ); warn "Ignoring my nodes prior to $timestamp_of_my_earliest_post\n"; @root_nodes_of_interest = PerlMonksTickers->only_new_nodes( $timestamp_of_my_earliest_post, @root_nodes_of_interest ); @root_nodes_of_interest or die "Sorry, you haven't posted any nodes in the last $ignore_my_posts_o +lder_than_days days.\n"; } @root_nodes_of_interest or die "Sorry, you haven't posted any nodes!\n"; my $timestamp_of_earliest_reply = timestamp_of_hours_ago( $window_in_h +ours ); warn "Showing only replies since $timestamp_of_earliest_reply\n\n"; for my $node ( @root_nodes_of_interest ) { my $hr = PerlMonksTickers->thread_nodes( id => $node->{'id'} ); my %ids; @ids{ keys %$hr, map @$_, values %$hr } = (); # while ( my($k,$v) = each %$hr ) { @ids{ $k, @$v } = (); } # altern +ative way. delete $ids{ $node->{'id'} }; # the root node is included in the set +. Ignore it. my $ts = $timestamp_of_earliest_reply; my @replies = map { PerlMonksTickers->any_node( node_id => $_ ) } ke +ys %ids; @replies = PerlMonksTickers->only_new_nodes( $ts, @replies ); @replies or next; printf( "%s (%s) %s\n", $node->{'createtime'}, $node->{'id'}, $node->{'title'}, ); print "has the following replies:\n"; for my $reply ( @replies ) { printf( " %s (%s) <%s> %s\n %s\n", $reply->{'createtime'}, $reply->{'node_id'}, $reply->{'author'}, $reply->{'title'}, ); } print "\n"; } sub timestamp_of_hours_ago { my $hours_ago = shift; my($sec,$min,$hour,$mday,$mon,$year) = localtime( time - $hours_ago * 60 * 60 ); sprintf "%04d-%02d-%02d %02d:%02d:%02d", $year+1900, $mon+1, $mday, $hour, $min, $sec; } __END__ Structures returned by user_nodes(): { id => 230228, title => 'Re: Edit your scratch', createtime => '2003-01-27 09:19:03', lastedit => '2003-01-27 09:19:03' lastupdate => '2003-01-27 09:35:09', } Structure returned by thread_nodes(): { 229651 => [ 229669, ], 229669 => [ 229699, 229846, ], 229699 => [ 229739, ], } Structures returned by any_node(): { node_id => 230258, type_id => 11, type => 'note' author_id => 114691, author => 'Aristotle', createtime => '2003-01-27 11:15:27', updatetime => '2003-01-27 11:18:32', title => 'Re^3: Edit your scratchpad... should be easier ', data => { root_node => 229965, parent_node => 230228, doctext => 'I have wanted to look at your code...' }, }

In reply to Check for recent replies to your posts by jdporter

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (6)
    As of 2020-02-18 03:07 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      What numbers are you going to focus on primarily in 2020?










      Results (74 votes). Check out past polls.

      Notices?