home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / ckscripts / weblog < prev    next >
Text File  |  2020-01-01  |  3KB  |  106 lines

  1. #!/usr/local/bin/wermit +
  2. #
  3. # THE FIRST LINE SHOULD INDICATE THE ACTUAL PATH OF C-KERMIT 9.0
  4. # and the script should be given execute permission.
  5. #
  6. # Usage: weblog filename
  7. #
  8. # Reads TSV-format web log for a bilingual English-Spanish website.
  9. # Extracts all Google searches.
  10. # Converts the coded search string into plain text.
  11. # If charset of search string is declared, converts it to ISO-8859-1.
  12. # If charset is not declared, it is tested for UTF-8 and converted.
  13. # Normalized search strings are tabulated using associative arrays.
  14. #
  15. # Illustrates:
  16. # . new \fsplit behavior - CK9.0
  17. # . new \fsqueeze() function
  18. # . message and if debug commands - New in CK9.0 Alpha.03
  19. # . decodehex function - New in CK9.0 Alpha.05
  20. # . stringtype function - New in CK9.0 Alpha.05
  21. # . use of MIME charset names - New in CK9.0 Alpha.05
  22. # . associative arrays (not new but little known)
  23. #
  24. # Frank da Cruz, Columbia University, April 2010
  25.  
  26. if not def \%1 exit 1 "usage: weblog logfilename"
  27.  
  28. fopen /read \%i \fcontents(\%1)
  29. if fail exit 1 
  30.  
  31. .lines = 0
  32. .google = 0
  33.  
  34. if def \$(DEBUG) set debug message on   # To print debugging messages
  35.  
  36. while true {
  37.     fread /line \%i line        # Read a record
  38.     if fail break            # End of file
  39.     incr lines                # Have record - count it
  40.     void \fsplit(\m(line),&a,\9,ALL,,1)    # Split it into fields
  41.     if not \findex(.html,\&a[5]) continue # Reject all non-HTML accesses
  42.     .isgoogle := \findex(.google.,\&a[8]) # Reject all non-Google accesses
  43.     if not isgoogle continue
  44.  
  45.     increment google            # Have a Google HTML record
  46.     void \fsplit(\&a[8],&b,&?,ALL,,1)    # Split it into 'clauses'
  47.     if debug show array b
  48.     undef charset string        # Clear result variables
  49.     for i 1 \fdim(&b) 1 {        # Loop through clauses
  50.         void \fsplit(\&b[i],&c,=,ALL)    # Split clause into ID and value
  51.         if equ "\&c[1]" "q" .string := \&c[2] # Query string
  52.         else if equ "\&c[1]" "ie" .charset := \&c[2] # Character set
  53.     }
  54.     if not def string continue        # No string - skip this record
  55.     if debug show mac charset string
  56.  
  57.     # Normalize the string....
  58.  
  59.     .string := \fsqueeze(\flower(\fdecodehex(\freplace(\m(string),+,\32))))
  60.     if debug show mac string
  61.     if def charset {
  62.         _increment cset<\fupper(\m(charset))>
  63.         if debug echo "CONVERTING [\m(string)] \m(charset)->ISO-8859-1"
  64.     .string := \fcvtcset(\m(string),\m(charset),iso-8859-1)
  65.     if debug show mac string
  66.     } else if equal "\fstringtype(\m(string))" "UTF8" {
  67.     .string := \fcvtcset(\m(string),UTF-8,iso-8859-1)
  68.     if debug show mac string
  69.         _increment cset<UNDECLARED_UTF-8_DETECTED> 
  70.     } else {
  71.         _increment cset<UNDECLARED>
  72.     }
  73.     .string := \fsubstitute(\m(string),┴╔═╙┌▄╤,ßΘφ≤·ⁿ±)
  74.     .string := \freplace(\m(string),espanol,espa±ol)
  75.     .string := \freplace(\m(string),ingles,inglΘs)
  76.     _increment search<\m(string)>
  77. }
  78. # Finished - Display statistics
  79.  
  80. echo
  81. echo "Records:  \flpad(\m(lines),8)"
  82. echo "Google:   \flpad(\m(google),8)"
  83. .n := \faaconvert(search,&a,&b)
  84. echo "Unique:   \flpad(\m(n),8)"
  85. .m := \faaconvert(cset,&c,&d)
  86. echo "Charsets: \flpad(\m(m),8)"
  87. echo
  88. echo Charsets by frequency...
  89. array sort /reverse /numeric &d &c
  90. for i 1 m 1 {
  91.     echo \flpad(\m(i),3). \flpad([\&d[i]],8) \&c[i]
  92. }
  93. if > n 20 .n = 20
  94. echo
  95. echo Top \m(n) searches by frequency...
  96. array sort /reverse /numeric &b &a
  97. for i 1 n 1 {
  98.     echo \flpad(\m(i),3). \flpad([\&b[i]],8) \&a[i]
  99. }
  100. exit 0
  101.  
  102. ; Local Variables:
  103. ; comment-column:40
  104. ; comment-start:"# "
  105. ; End:
  106.