whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curc...@apache.org
Subject [whimsy] branch master updated: Transform csv docket to json
Date Sat, 22 Apr 2017 21:46:49 GMT
This is an automated email from the ASF dual-hosted git repository.

curcuru 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  bfeb231   Transform csv docket to json
bfeb231 is described below

commit bfeb23138b62ab9cbcd060d2881817fdb4bd9866
Author: Shane Curcuru <asf@shanecurcuru.org>
AuthorDate: Sat Apr 22 17:46:44 2017 -0400

    Transform csv docket to json
    
    Transform docket.csv, which changes rarely, into a JSON file for use in
    other scripts/websites
---
 www/test/test.cgi | 46 +++++++++++++++++++++-------------------------
 1 file changed, 21 insertions(+), 25 deletions(-)

diff --git a/www/test/test.cgi b/www/test/test.cgi
index 529ca51..471f213 100755
--- a/www/test/test.cgi
+++ b/www/test/test.cgi
@@ -1,5 +1,5 @@
 #!/usr/bin/env ruby
-# Test file for various experiments
+# Transform docket.csv into JSON structure for other uses
 $LOAD_PATH.unshift File.realpath(File.expand_path('../../../lib', __FILE__))
 require 'csv'
 require 'json'
@@ -9,32 +9,28 @@ require 'wunderbar/bootstrap'
 require 'net/http'
 require 'whimsy/asf/themes'
 
-PAGETITLE = 'Listing of Apache Registered Trademarks'
+MNAM = 'TrademarkName'
 brand_dir = ASF::SVN['private/foundation/Brand']
-
-_json do
-  docket = CSV.read("#{brand_dir}/docket.csv", headers:true)
-  docketcols = %w[ TrademarkName TrademarkStatus CountryName Class RegNumber ]
-  dockethash = {}
-  # Create hash based on pmc with aggregated data
-  docket.each do |r|
-    r << ['pmc', r['TrademarkName'].downcase.sub('.org','').sub(' & design','')]
-    key = r['pmc'].to_sym
-    if dockethash.key?(key)
-      # Aggregate specific values
-      docketcols.each do |col|
-        dockethash[key][col] |= [r[col]]
-      end
-
+csv = CSV.read("#{brand_dir}/docket.csv", headers:true)
+docket = {}
+csv.each do |r|
+  r << ['pmc', r[MNAM].downcase.sub('.org','').sub(' & design','')]
+  key = r['pmc'].to_sym
+  mrk = {}
+  %w[ TrademarkStatus CountryName Class AppNumber RegNumber ClassGoods ].each do |col|
+    mrk[col] = r[col]
+  end  
+  if not docket.key?(key)
+    docket[key] = { r[MNAM] => [mrk] }
+  else
+    if not (docket[key]).key?(r[MNAM])
+      docket[key][r[MNAM]] = [mrk]
     else
-      # Create first copy of the pmc
-      dockethash[key] = {}
-      docketcols.each do |col|
-        dockethash[key][col] = [r[col]]
-      end
-      # Hack: only use first Goods
-      dockethash[key]['ClassGoods'] = r['ClassGoods']
+      docket[key][r[MNAM]] << mrk      
     end
   end
-  dockethash
+end
+
+_json do
+  docket
 end

-- 
To stop receiving notification emails like this one, please contact
['"commits@whimsical.apache.org" <commits@whimsical.apache.org>'].

Mime
View raw message