sales 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION.yml +1 -1
  2. data/bin/sale +67 -101
  3. metadata +1 -1
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 0
4
- :patch: 3
4
+ :patch: 4
5
5
  :build:
data/bin/sale CHANGED
@@ -29,7 +29,7 @@ USAGE = <<-EGASU
29
29
  #{'sale weekly'.green}
30
30
 
31
31
  get and present the last daily summary report
32
- #{'sale'}.green
32
+ #{'sale'.green}
33
33
 
34
34
  get and present a daily summary report for a date
35
35
  #{'sale.rb YYYYMMDD'.green}
@@ -64,7 +64,7 @@ else
64
64
  end
65
65
 
66
66
  #prepare the java runtime classpath for the Autoingestion.class
67
- classpath = File.join(File.dirname(__FILE__), %w[..])
67
+ @classpath = File.join(File.dirname(__FILE__), %w[..])
68
68
 
69
69
  #identifiers
70
70
  PRODUCT_TYPE_IDENTIFIER = {
@@ -288,7 +288,57 @@ def compute_and_present(reports)
288
288
  puts "\n\n"
289
289
  end
290
290
 
291
+ # Download a report with the autoingest java tool
292
+ #
293
+ #
294
+ def autoingest(username, password, vendorId, options = "Sales Daily Summary")
295
+ #call the java program and fetch the file
296
+ e = `java -cp #{@classpath} Autoingestion #{@username} #{@password} #{@vendorId} #{options}`
297
+ report_file = e.split("\n").first
298
+ if File.exists? report_file
299
+ f = `gzip -df #{report_file}`
300
+ else
301
+ puts "#{e}\n".red
302
+ end
303
+ end
304
+
305
+ # Downloads daily reports
306
+ #
307
+ #
308
+ def get_daily_reports
309
+ # Daily reports are available only for past 14 days, please enter a date within past 14 days.
310
+ first_date = Date.today
311
+ (1..14).each do |i|
312
+ date = (first_date - i).to_s.gsub('-', '')
313
+ puts "\nGetting Daily Sales Report for #{date}\n"
314
+ filename = "S_D_#{@vendorId}_#{date}.txt"
315
+ unless File.exists? filename #download unless there already is a file
316
+ autoingest(@username, @password, @vendorId, "Sales Daily Summary #{date}")
317
+ end
318
+ end # 1..14.each
319
+ end
320
+
321
+ # Downloads weekly reports
322
+ #
323
+ #
324
+ def get_weekly_reports
325
+ # Weekly reports are available only for past 13 weeks, please enter a weekend date within past 13 weeks.
326
+ first_date = Date.today
327
+ (1..13).each do |i| #13 weeks
328
+ date = (first_date - i*7)
329
+ day_increment = (0 - date.cwday) % 7
330
+ day_increment = 7 if day_increment == 0
331
+ next_sunday = date + day_increment
332
+ formatted_date = next_sunday.to_s.gsub('-', '')
333
+ puts "\nGetting Weekly Sales Report for #{formatted_date}\n"
334
+ filename = "S_W_#{@vendorId}_#{formatted_date}.txt"
335
+ unless File.exists? filename #download unless there already is a file
336
+ autoingest(@username, @password, @vendorId, "Sales Weekly Summary #{formatted_date}")
337
+ end
338
+ end # 1..13.each
339
+ end
291
340
 
341
+ #-------------------------------------------------------------------------------------------------------------------------------
292
342
  #begin to show visible light of this program by displaying its name, version and creator
293
343
  puts "\nSales v#{VERSION}".red + " created by Your Headless Standup Programmer http://kitschmaster.com".dark_blue if @beVerbose
294
344
 
@@ -303,9 +353,15 @@ elsif ARGV[0] == "daily" || ARGV[0] == "weekly"
303
353
  #collect the report files
304
354
  dir_filter = ARGV[0] == "daily" ? "D" : "W" #the daily or the weekly files
305
355
  reports = Dir["S_#{dir_filter}_*.txt"].uniq.compact
306
- if reports.empty?
356
+ if reports.empty?
357
+ #no reports, try downloding them first
358
+ puts "\nDownloading reports first...".red
359
+ method("get_#{ARGV[0]}_reports".to_sym).call #dynamically instantiating a method and calling on it
360
+ reports = Dir["S_#{dir_filter}_*.txt"].uniq.compact #reload reports list
361
+ end
362
+ if reports.empty? #recheck
307
363
  #no reports
308
- puts "\nPlease download reports first.".red
364
+ puts "\nDownload reports first. Use command:".red
309
365
  puts "sale get:#{ARGV[0].split(':').last}\n".green
310
366
  else
311
367
  #compute and present the collected reports
@@ -314,116 +370,26 @@ elsif ARGV[0] == "daily" || ARGV[0] == "weekly"
314
370
  #-----------------------------------------------------------------------------------------------------------------------------
315
371
  elsif ARGV[0] == "get:daily"
316
372
  #-----------------------------------------------------------------------------------------------------------------------------
317
- # Daily reports are available only for past 14 days, please enter a date within past 14 days.
318
- first_date = Date.today
319
- (1..14).each do |i|
320
- date = (first_date - i).to_s.gsub('-', '')
321
- puts "\nGetting Daily Sales Report for #{date}\n"
322
- filename = "S_D_#{@vendorId}_#{date}.txt"
323
- unless File.exists? filename #download unless there already is a file
324
- #call the java program and fetch the file
325
- e = `java -cp #{classpath} Autoingestion #{@username} #{@password} #{@vendorId} Sales Daily Summary #{date}`
326
- report_file = e.split("\n").first
327
- if File.exists? report_file
328
- f = `gzip -df #{report_file}`
329
- else
330
- puts "#{e}\n".red
331
- end
332
- end
333
- end # 1..14.each
373
+ get_daily_reports
334
374
  #-----------------------------------------------------------------------------------------------------------------------------
335
375
  elsif ARGV[0] == "get:weekly"
336
376
  #-----------------------------------------------------------------------------------------------------------------------------
337
- # Weekly reports are available only for past 13 weeks, please enter a weekend date within past 13 weeks.
338
- first_date = Date.today
339
- (1..13).each do |i| #13 weeks
340
- date = (first_date - i*7)
341
- day_increment = (0 - date.cwday) % 7
342
- day_increment = 7 if day_increment == 0
343
- next_sunday = date + day_increment
344
- formatted_date = next_sunday.to_s.gsub('-', '')
345
- puts "\nGetting Weekly Sales Report for #{formatted_date}\n"
346
- filename = "S_W_#{@vendorId}_#{formatted_date}.txt"
347
- unless File.exists? filename #download unless there already is a file
348
- #call the java program and fetch the file
349
- e = `java -cp #{classpath} Autoingestion #{@username} #{@password} #{@vendorId} Sales Weekly Summary #{formatted_date}`
350
- report_file = e.split("\n").first
351
- if File.exists? report_file
352
- f = `gzip -df #{report_file}`
353
- else
354
- puts "#{e}\n".red
355
- end
356
- end
357
- end # 1..13.each
377
+ get_weekly_reports
358
378
  #-----------------------------------------------------------------------------------------------------------------------------
359
379
  else
360
380
  #-----------------------------------------------------------------------------------------------------------------------------
361
381
  # no argument or date in format YYYYMMDD
362
- #get sales report for date
382
+ #get sales report for default date
363
383
  @date = ARGV[0]
364
384
  date = (Date.today - 1).to_s.gsub('-', '')
365
385
  date = @date if ARGV[0]
366
386
  puts "\nDaily Sales Report for #{date}\n"
367
387
  filename = "S_D_#{@vendorId}_#{date}.txt"
368
388
  unless File.exists? filename #download unless there already is a file
369
- #call the java program and fetch the file
370
- e = `java -cp #{classpath} Autoingestion #{@username} #{@password} #{@vendorId} Sales Daily Summary #{date}`
371
- report_file = e.split("\n").first
372
- if File.exists? report_file
373
- f = `gzip -df #{report_file}`
374
- else
375
- puts "#{e}\n".red
376
- end
389
+ autoingest(@username, @password, @vendorId, "Sales Daily Summary #{date}")
377
390
  end
391
+ #compute and present the report
378
392
  compute_and_present([filename])
379
- =begin
380
- if File.exists? filename #only if there is data
381
- #calculate totals
382
- report_data = File.open(filename, "rb").read
383
- report = parse(report_data)
384
- apps = {}
385
- total_payed_units = 0
386
- total_inapp_units = 0
387
- total_free_units = 0
388
- total_updated_units = 0
389
- report.each do |item|
390
- sku = item[:sku] #group data by app sku
391
- if apps.has_key? sku #app is already cached
392
- app = apps[sku]
393
- else #initially insert app
394
- app = {:sku=>sku, :title=>item[:title], :sold_units=>0, :updated_units=>0}
395
- apps[sku] = app
396
- end
397
- #count units
398
- if SALE_IDENTS.include? item[:product_type_id] #count sales
399
- app[:sold_units] += item[:units]
400
- if item[:customer_price]==0 #a free app
401
- total_free_units += item[:units]
402
- else
403
- total_payed_units += item[:units]
404
- end
405
- elsif INAPP_SALE_IDENTS.include? item[:product_type_id]
406
- app[:sold_units] += item[:units]
407
- total_inapp_units += item[:units]
408
- elsif UPDATE_IDENTS.include? item[:product_type_id] #count updates
409
- app[:updated_units] += item[:units]
410
- total_updated_units += item[:units]
411
- end
412
- end
413
-
414
- #report
415
- puts "\n" + "Product".ljust(40).blue + ": " +"Downloads".green + " / " + "Updates".green
416
- puts "____________________________________________________________".yellow
417
- apps.each do |app_sku, app|
418
- puts "#{app[:title].ljust(40).blue}: #{app[:sold_units].to_s.ljust(10).green} / #{app[:updated_units].to_s.rjust(7).dark_green}"
419
- end
420
- puts "____________________________________________________________".yellow
421
- puts "#{'InApp Purchases'.ljust(40).green}: #{total_inapp_units}"
422
- puts "#{'Payed Downloads'.ljust(40).green}: #{total_payed_units}"
423
- puts "#{'Free Downloads'.ljust(40).dark_green}: #{total_free_units}"
424
- puts "#{'Updates'.ljust(40).dark_green}: #{total_updated_units}"
425
- puts "\n"
426
- end
427
- =end
428
393
  #-----------------------------------------------------------------------------------------------------------------------------
429
- end
394
+ end
395
+ #-------------------------------------------------------------------------------------------------------------------------------
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: sales
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.3
5
+ version: 0.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mihael