whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [whimsy] branch master updated: Allow stats to be sorted within domains
Date Sun, 31 May 2020 10:53:24 GMT
This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new e479ebc  Allow stats to be sorted within domains
e479ebc is described below

commit e479ebc79941eb71d16fc91fefa546d6131cd2c2
Author: Sebb <sebb@apache.org>
AuthorDate: Sat May 30 12:35:39 2020 +0100

    Allow stats to be sorted within domains
---
 tools/ponyapi.rb | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/tools/ponyapi.rb b/tools/ponyapi.rb
index 29db95c..896c647 100755
--- a/tools/ponyapi.rb
+++ b/tools/ponyapi.rb
@@ -83,18 +83,21 @@ module PonyAPI
 
   # Download one month of stats as a JSON
   # Must supply cookie = 'ponymail-logged-in-cookie' if a private list
-  def get_pony_stats(dir, list, subdomain, year, month, cookie=nil)
+  def get_pony_stats(dir, list, subdomain, year, month, cookie=nil, sort_list=false)
     cookie=get_cookie() if cookie == 'prompt'
     args =  make_args(list, subdomain, year, month)
     uri, request, response = fetch_pony(PONYSTATS % args, cookie)
     if response.code == '200' then
       openfile(dir, STATSMBOX % args) do |f|
         begin
-          f.puts JSON.pretty_generate(JSON.parse(response.body))
+          jzon = JSON.parse(response.body)
+          jzon = Hash[jzon.sort] if sort_list
+          f.puts JSON.pretty_generate(jzon)
         rescue JSON::JSONError
           begin
             # If JSON threw error, try again forcing to UTF-8 (may lose data)
             jzon = JSON.parse(response.body.encode('UTF-8', :invalid => :replace, :undef
=> :replace))
+            jzon = Hash[jzon.sort] if sort_list
             f.puts JSON.fast_generate(jzon, {:max_nesting => false, :indent => ' '})
           rescue JSON::JSONError => e
             puts "WARN:get_pony_stats(#{uri.request_uri}) #{e.message} #{e.backtrace[0]},
continuing without pretty"


Mime
View raw message