#!load hmessage.hsm VarSet( $SttTime, Time ) # SttTime time when the script was started Var( $SGrpNam, $TGrpNam, $GrpHdl, $ArtMin, $ArtMax, $ArtNo, $ArtDatH, $ArtFrom, $TempMsg) # SGrpNam name of newsgroup to be checked # TGrpNam name of newsgroup to post results to # GrpHdl handle for selected group # ArtMin first article locally available in group # ArtMax last article locally available in group # ArtNo currently processed article number # ArtDatH Date-header of current article # ArtFrom From-header of current article # TempMsg ArtTxt converted to list, used for ArtDatH # Later used to store final message to be posted Var( $ArtDatU, $SttDate, $EndDate, $TzDiff, $yy, $mo, $dd, $hh, $mi, $ss , $Tzone) # ArtDatU date and time of current article in Unix-format # SttDate articles between SttDate and EndDate... # EndDate ...will be counted in the statistics # TzDiff difference between local time and GMT, in Unix-format # others year, month, day, hours, minutes, seconds # Tzone timezone Var( $Counter, $NoArtFr, $Stats, $StrLen, $TotArt, $Yesterday, $OldPos ) # Counter list containing poster-names (complete From-header) and their number of posts # NoArtFr number of articles in list Counter from current poster (ArtFrom) # Stats final list, with formatted strings containing article count and poster # StrLen length of string containing From + "=" + Str($NoArt, 5, " ") # TotArt total number of articles posted # Yesterday date of yesterday needs to be stored for final message subject # OldPos position of previous entry, used for position(=ranking) of poster VarSet( $OldCount, "" ) # OldCount number of articles posted by previous list-entry; used for position of poster # ScriptPriority( 6 ) # hoogste prioriteit; uitzetten bij testen $SGrpNam = "nl.test" # if no (valid) parameter is given, we'll use nl.test as the source $TGrpNam = "internal.test" # if no (valid) parameter is given, we'll use nl.test as the target If( ParamCount = 2 ) # do we have two parameters? If( HamGroupIndex( ParamStr( 1 ) ) >= 0 ) # Is paramater 1 valid (known) groupname? $SGrpNam = ParamStr( 1 ) # if so, the parameter is the selected group Else Warning( "Parameter 1 (source) isn't a (known) newsgroup; nl.test will be used.") EndIf If( HamGroupIndex( ParamStr( 2 ) ) >= 0 ) # Is paramater 2 valid (known) groupname? $TGrpNam = ParamStr( 2 ) # if so, the parameter is the selected group Else Warning( "Parameter 2 (target) isn't a (known) newsgroup; nl.test will be used.") EndIf Else Warning( "This script requires two parameters: a source-, and a target-group. The newsgroup nl.test will be used for both now." ) EndIf $GrpHdl = HamGroupOpen( $SGrpNam ) If( $GrpHdl >= 0 ) # no error? $ArtMin = HamArtNoMin( $GrpHdl ) # get first article locally available $ArtMax = HamArtNoMax( $GrpHdl ) # get last article locally available $TempMsg = ArtAlloc # list containing currently processed article $Counter = ListAlloc # list containing poster-names and their number of posts # Set start- and endtime (yesterday 0:00:00 - yesterday 23:59:59) DecodeTime( Time-24*60*60, $yy, $mo, $dd, 0, 0 ,0 ) # get date of yesterday, store in $yy,$mo,$dd $Yesterday = $dd + "-" + $mo + "-" + $yy $TzDiff = TimeGMT - Time # RfcDate_to_secsgmt works in GMT, so all times need to be adapted $SttDate = EncodeTime( $yy, $mo, $dd, 00, 00, 00 ) + $TzDiff # start at yesterday, 00:00:00 $EndDate = EncodeTime( $yy, $mo, $dd, 23, 59, 59 ) + $TzDiff # end at yesterday, 23:59:59 # pick articles posted yesterday, count the number of articles for every poster and the total number of articles $TotArt = 0 For($ArtNo, $ArtMin, $ArtMax, 1) ArtSetHeaders( $TempMsg, HamArtText( $GrpHdl, $ArtNo ) ) # store article headers in list (body is ignored) $ArtDatH = ArtGetHeader( $TempMsg, "Date:" ) # get Date-header from list If( Len( $ArtDatH ) > 17 ) # (Officially, seconds are optional, but this statsbot *doesn't work* when they are ommitted!) Re_Parse( $ArtDatH, "^\D*(\d+) (\w+) (\d+) (\d+):(\d+):(\d+) ?(\S+)?", $dd, $mo, $yy, $hh,$mi,$ss, $Tzone ) # extract all neccessary info from Date-header $mo = Pos( Lowercase( $mo ), " jan feb mar apr may jun jul aug sep oct nov dec" ) / 4 # convert alphabetic month to numeric $yy = Int( IIf( Len( $yy ) == 2, "20" + $yy, $yy ) ) # 2-digit year allowed, according to RFC2822. Needs to be converted to 4-digit. If( Re_Match( $Tzone, "^.\d+" ) ) # Is $Tzone a numeric code? $Tzone = Int( $Tzone ) * 36 Else # Or an alphabetic code? $Tzone = ICase( Uppercase($Tzone), "GMT", 0, _ "UT", 0, _ "MET", -36000, _ "WET", -36000, _ "EDT", -14400, _ "EST", -18000, _ "CDT", -18000, _ "CST", -21600, _ "MDT", -21600, _ "MST", -25200, _ "PDT", -25200, _ "PST", -28800, _ else, 0 ) EndIf $ArtDatU= EncodeTime( $yy, $mo, Int($dd), Int($hh), Int($mi), Int($ss)) - $Tzone # convert decoded Date-header to single-number Unix-date If( $ArtDatU >= $SttDate && $ArtDatU <= $EndDate) # article posted yesterday? Inc( $TotArt ) $ArtFrom = DecodeMimeHeaderString( ArtGetHeader( $TempMsg, "From:" ) ) # store From-header for source-readability $NoArtFr = Int( ListGetKey( $Counter, $ArtFrom )) # get number of articles already counted from current poster Inc( $NoArtFr ) # add current article ListSetKey( $Counter, $ArtFrom, Str( $NoArtFr, 5, " " ) ) # store new number of articles in list EndIf EndIf EndFor # combine article count and poster in single string, and sort $Stats = ListAlloc # list with formatted strings containing article count and poster For($ArtNo, 0, ListCount($Counter)-1, 1) $StrLen = Len( ListGet( $Counter, $ArtNo ) ) ListAdd( $Stats, Copy( ListGet( $Counter, $ArtNo ), $StrLen-4 ) + " " + Copy( ListGet( $Counter, $ArtNo ), 1, $StrLen-6 ) ) # add NoArt, 3 spaces, From EndFor ListSort( $Stats ) # compose final message to be posted, in $TempMsg ArtFree( $TempMsg ) # Free art-list to re-use $TempMsg for stats to be posted $TempMsg = ListAlloc # list containing message to be posted MsgSetHeader( $TempMsg, "Newsgroups:", $TGrpNam ) # post to selected target-group MsgSetHeader( $TempMsg, "From:", "RoBot Spanjaard " ) MsgSetHeader( $TempMsg, "Subject:", "Statistics for " + $SGrpNam + ", articles posted on " + $Yesterday ) MsgSetHeader( $TempMsg, "Content-Type:", "text/plain; charset=""ISO-8859-1""" ) MsgSetHeader( $TempMsg, "Content-Transfer-Encoding:", "7bit" ) MsgSetHeader( $TempMsg, "Lines:", ListCount( $Stats ) + 9 ) MsgSetHeader( $TempMsg, "X-Face:", "25q/#TY26#_.U/^;=Ggr`875+Sr^)7~U)eSNFy""~:n0p;$XxMl0N=gER'l&z3:g}rm.H0(NcQ}?<:eP*\aQ]L3!Ao5FWeIc8dDjQ_uGcY\(_%xXx#:eWSjxxkfH9/6`h8T9}l97xw%eM6?O/t)Eou6f`wW[l]*XZrhx$z{/P!^gGwbtj^CBjVoV\;+xpCd7_~RW3#Wn9mehxh2XYrSWTzG" ) ListAdd( $TempMsg, "" ) ListAdd( $TempMsg, "POS. POSTS FROM" ) # Add statistics. Reverse order, to put highest number of posts at the top of the list. For($ArtNo, ListCount($Stats)-1, 0, -1) If( Copy( ListGet( $Stats, $ArtNo ), 1, 5) == $OldCount ) # same count as previous entry? # add position of previous poster to message ListAdd( $TempMsg, Str($OldPos,3," ") + " " + ListGet( $Stats, $ArtNo) ) # Add position and count+poster to message Else ListAdd( $TempMsg, Str(ListCount($Stats)-$ArtNo,3," ") + " " + ListGet( $Stats, $ArtNo) ) # Add position and count+poster to message $OldPos = ListCount($Stats) - $ArtNo EndIf $OldCount = Copy( ListGet( $Stats, $ArtNo ), 1, 5) EndFor ListAdd( $TempMsg, " -----" ) ListAdd( $TempMsg, "TOTAL" + Str( $TotArt, 6, " ") ) ListAdd( $TempMsg, "" ) ListAdd( $TempMsg, Str( $ArtMax - $ArtMin + 1 ) + " records processed in " + Str( Time - $SttTime ) + " seconds." ) ListAdd( $TempMsg, "" ) ListAdd( $TempMsg, "-- " ) ListAdd( $TempMsg, "RoBot Spanjaard" ) # 'Post' message to News.Out ListSave( $TempMsg, "Groups\News.out\Stats_" + $SGrpNam + "_" + Time + ".msg" ) ListFree( $TempMsg ) ListFree( $Counter ) ListFree( $Stats ) EndIf HamGroupClose( $GrpHdl ) ScriptPriority( 3 ) Quit