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 d438f9c Use fixed length year and month fields
d438f9c is described below
commit d438f9c9478a2772f56359e51acce3b865e02d44
Author: Sebb <[email protected]>
AuthorDate: Wed Dec 13 00:49:43 2017 +0000
Use fixed length year and month fields
fetch_pony should be private
---
tools/ponyapi.rb | 56 ++++++++++++++++++++++++++++++++------------------------
1 file changed, 32 insertions(+), 24 deletions(-)
diff --git a/tools/ponyapi.rb b/tools/ponyapi.rb
index 5dc09fa..205cc0f 100644
--- a/tools/ponyapi.rb
+++ b/tools/ponyapi.rb
@@ -15,33 +15,18 @@ module PonyAPI
extend self
- # Fetch a Ponymail API, with optional logged-in cookie
- def fetch_pony(uri, cookie)
- uri = URI.parse(uri)
- Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |https|
- request = Net::HTTP::Get.new(uri.request_uri)
- request['Cookie'] = "ponymail=#{cookie}" if cookie != ''
- response = https.request(request)
- if response.code =~ /^3\d\d/
- fetch_pony response['location'], cookie
- else
- return uri, request, response
- end
- end
- end
-
# 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)
if subdomain.nil? || subdomain == ''
getlist = "#{list}&domain=apache.org"
- fname = "#{list}-apache-org-#{year}#{month}-stats.json"
+ fname = "#{list}-apache-org-%04d%02d-stats.json" % [year, month]
else
getlist = "#{list}&domain=#{subdomain}.apache.org"
- fname = "#{list}-#{subdomain}-apache-org-#{year}#{month}-stats.json"
+ fname = "#{list}-#{subdomain}-apache-org-%04d%02d-stats.json" % [year,
month]
end
uri, request, response =
fetch_pony("#{PONYSTATS}#{getlist}&d=#{year}-#{month}", cookie)
- if response.code =~ /200/ then
+ if response.code == '200' then
File.open(File.join("#{dir}", "#{fname}"), "w") do |f|
jzon = JSON.parse(response.body)
begin
@@ -52,7 +37,7 @@ module PonyAPI
end
end
else
- puts "ERROR:get_pony_stats(#{uri.request_uri}) returned code
#{response.code}"
+ puts "ERROR:get_pony_stats(#{uri.request_uri}) returned code
#{response.code.inspect}"
end
end
@@ -71,18 +56,18 @@ module PonyAPI
def get_pony_mbox(dir, list, subdomain, year, month, cookie)
if subdomain.nil? || subdomain == ''
getlist = "#{list}@apache.org"
- fname = "#{list}-apache-org-#{year}#{month}.mbox"
+ fname = "#{list}-apache-org-%04d%02d.mbox" % [year, month]
else
getlist = "#{list}@#{subdomain}.apache.org"
- fname = "#{list}-#{subdomain}-apache-org-#{year}#{month}.mbox"
+ fname = "#{list}-#{subdomain}-apache-org-%04d%02d.mbox" % [year, month]
end
uri, request, response =
fetch_pony("#{PONYMBOX}#{getlist}&date=#{year}-#{month}", cookie)
- if response.code =~ /^200/
+ if response.code == '200'
File.open(File.join("#{dir}", "#{fname}"),
"w:#{response.body.encoding}") do |f|
f.puts response.body
end
else
- puts "ERROR:get_public_mbox(#{uri}) returned code #{response.code}"
+ puts "ERROR:get_public_mbox(#{uri}) returned code
#{response.code.inspect}"
end
end
@@ -95,4 +80,27 @@ module PonyAPI
sleep(1) # Be nice to the server; mboxes take effort
end
end
-end
\ No newline at end of file
+
+ private
+
+ # Fetch a Ponymail API, with optional logged-in cookie
+ def fetch_pony(uri, cookie)
+ uri = URI.parse(uri)
+ Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |https|
+ request = Net::HTTP::Get.new(uri.request_uri)
+ request['Cookie'] = "ponymail=#{cookie}" if cookie != ''
+ response = https.request(request)
+ if response.code =~ /^3\d\d/
+ fetch_pony response['location'], cookie
+ else
+ return uri, request, response
+ end
+ end
+ end
+
+end
+
+if __FILE__ == $0
+# PonyAPI.get_pony_mbox('.', 'dev', 'whimsical', 2017, 01, nil)
+# PonyAPI.get_pony_stats('.', 'dev', 'whimsical', 2017, 01, nil)
+end
--
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].