adncv 0.4 → 0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b240d2b88fc0750e717354a51149cdd9c2cea31
4
- data.tar.gz: edff5c392d2afa3cda914313256fa29d7084e57f
3
+ metadata.gz: 3f20c8ba586d6e4f4ecca3642f47d4eb3b33f95d
4
+ data.tar.gz: b2fe538c7d36fb0ea9f782f256401fe23e651dc6
5
5
  SHA512:
6
- metadata.gz: 35d69ebc3988d957f7ce8b1f324f4005b3772439abc87e1d811ece7c4cac84dad0981c4fcf22fbe7494a1be6de65b6104e832b2a13681a2f92ebb6418311fdb0
7
- data.tar.gz: 4baaad2c56a997471b09d02bd86524b6122f78f6aec6b214c39e772fd7dfea1b441aedb1a1c761eab87c31a1f0cc2032df4ae0a2b1f2a54911ffa9e6018755a7
6
+ metadata.gz: 1f1ba1a0b1dbd8e53d653ce2d1fdc8359e22aea3fa1344f41089bcbe381f384dbfbfda1baa11706d7c7d70a609657b3cf4fac806a967cfa6d19d6ad7bee67b9e
7
+ data.tar.gz: cd945e84a3042adb5518c0c6b608f65f8cf27c7c383b355a308b7676b6307bece8c1f2a05eed2f71296f4341bf88618167d92dca2df4c75f886d5a77d33ad448
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ["lib"]
21
21
 
22
22
  spec.add_dependency "thor", "~> 0.19"
23
+ spec.add_dependency "terminal-table", "~> 1.4"
23
24
 
24
25
  spec.add_development_dependency "bundler", "~> 1.7"
25
26
  spec.add_development_dependency "rake", "~> 10.0"
@@ -1,3 +1,7 @@
1
+ # 0.5
2
+
3
+ Table view.
4
+
1
5
  # 0.4
2
6
 
3
7
  Monthly posting frequency.
@@ -1,5 +1,6 @@
1
1
  require 'thor'
2
2
  require 'json'
3
3
  require 'date'
4
+ require 'terminal-table'
4
5
  require_relative "ADNCV/version"
5
6
  require_relative "ADNCV/app"
@@ -7,17 +7,20 @@ module ADNCV
7
7
 
8
8
  desc "display", "Show your account statistics (-d)"
9
9
  map "-d" => :display
10
- option :full, aliases: "-f", type: :boolean, desc: "Display full details: links, users, etc"
10
+ option :full, aliases: "-f", type: :boolean, desc: "Display full details: links, users, etc", default: false
11
+ # option :messages, aliases: "-m", type: :boolean, desc: "Reads messages file instead of posts file", default: false
12
+ option :table, aliases: "-t", type: :boolean, desc: "Displays data in a table", default: true
11
13
  def display(file)
12
- analyze(file)
14
+ analyze(file, options)
13
15
  @display.show(@data, options)
14
16
  end
15
17
 
16
18
  desc "export", "Export your account statistics (-e)"
17
19
  map "-e" => :export
18
20
  option :path, aliases: "-p", type: :string, desc: "Specify the path for the exported file"
21
+ # option :messages, aliases: "-m", type: :boolean, desc: "Reads messages file instead of posts file"
19
22
  def export(file)
20
- analyze(file)
23
+ analyze(file, options)
21
24
  @data.export(options)
22
25
  @display.exported(@data.export_path)
23
26
  end
@@ -31,11 +34,11 @@ module ADNCV
31
34
 
32
35
  private
33
36
 
34
- def analyze(file)
37
+ def analyze(file, options)
35
38
  @data = Data.new
36
39
  @display = Display.new
37
40
  @display.analyzing
38
- @data.extract(file)
41
+ @data.extract(file, options)
39
42
  end
40
43
 
41
44
  end
@@ -2,18 +2,39 @@
2
2
  module ADNCV
3
3
  class Data
4
4
 
5
- attr_reader :filename, :count, :leadings, :without_mentions, :mentions_not_directed, :replies, :mentions_not_replies, :with_links, :sources, :all_links, :directed_users, :names, :clients, :mentions, :all_clients, :all_mentioned, :reposts, :stars, :been_replied, :freq
5
+ attr_reader :filename, :count, :leadings, :without_mentions, :mentions_not_directed, :replies, :mentions_not_replies, :with_links, :sources, :all_links, :directed_users, :names, :clients, :mentions, :all_clients, :all_mentioned, :reposts, :stars, :been_replied, :freq, :type, :all_directed
6
6
  attr_accessor :export_path
7
7
 
8
- def initialize
8
+ # def initialize
9
9
 
10
- end
10
+ # end
11
11
 
12
- def extract(file)
12
+ def extract(file, options = {})
13
13
  @filename = file
14
- decoded = JSON.parse(File.read(file))
15
- @count = decoded.size
14
+ @decoded = JSON.parse(File.read(file))
15
+
16
+ if options["messages"]
17
+ @type = :messages
18
+ extract_messages(file)
19
+ else
20
+ @type = :posts
21
+ extract_posts(file)
22
+ end
23
+ end
16
24
 
25
+ def extract_messages(file)
26
+ messages = Hash.new(0)
27
+ @decoded.each do |message|
28
+ messages[message["channel_id"]] += 1
29
+ end
30
+ puts JSON.pretty_generate(messages)
31
+
32
+ #
33
+ exit
34
+ end
35
+
36
+ def extract_posts(file)
37
+ @count = @decoded.size
17
38
  links = []
18
39
  @mentions = 0
19
40
  @leadings = 0
@@ -28,7 +49,7 @@ module ADNCV
28
49
  @clients = Hash.new(0)
29
50
  @freq = Hash.new(0)
30
51
 
31
- decoded.each do |post|
52
+ @decoded.each do |post|
32
53
  @clients[post["source"]["name"]] += 1
33
54
  m = post["entities"]["mentions"]
34
55
  l = post["entities"]["links"]
@@ -66,18 +87,17 @@ module ADNCV
66
87
  @freq[[dd.year, dd.month]] += 1
67
88
  end
68
89
 
69
- all_directed = directed.sort_by {|k,v| v}
90
+ @all_directed = directed.sort_by {|k,v| v}
70
91
  @all_clients = @clients.sort_by {|k,v| v}
71
92
  @all_mentioned = mentioned.sort_by {|k,v| v}.uniq
72
93
  @all_links = links.uniq.sort
73
94
  @names = @all_mentioned.map {|k,v| "@#{k} (#{v})"}
74
95
  @sources = @all_clients.map {|k,v| "#{k} (#{v})"}
75
- @directed_users = all_directed.uniq.map {|k,v| "@#{k} (#{v})"}
96
+ @directed_users = @all_directed.uniq.map {|k,v| "@#{k} (#{v})"}
76
97
 
77
98
  @without_mentions = count - @mentions
78
99
  @mentions_not_directed = @mentions - @leadings
79
100
  @mentions_not_replies = @mentions - @replies
80
-
81
101
  end
82
102
 
83
103
  def export(options)
@@ -6,6 +6,13 @@ module ADNCV
6
6
  @thor = Thor::Shell::Color.new
7
7
  end
8
8
 
9
+ def init_table(title = 'ADNCV')
10
+ Terminal::Table.new do |t|
11
+ t.style = { :width => 80 }
12
+ t.title = title
13
+ end
14
+ end
15
+
9
16
  def banner
10
17
  <<-ADNCV
11
18
  ___ ___ _ ________ __
@@ -18,7 +25,8 @@ module ADNCV
18
25
 
19
26
  def version
20
27
  puts banner()
21
- @thor.say_status :version, "#{VERSION}", :red
28
+ @thor.say_status :version, "#{VERSION}", :yellow
29
+ @thor.say_status :source, "http://github.com/ericdke/ADNCV", :green
22
30
  puts "\n"
23
31
  end
24
32
 
@@ -41,28 +49,67 @@ module ADNCV
41
49
 
42
50
  def show(data, options)
43
51
  clear_screen()
44
- puts "Total posts:".ljust(50) + "#{data.count}" + "\n\n"
45
- puts "Without mentions:".ljust(50) + "#{data.without_mentions}" + "\n\n"
46
- puts "Directed to a user:".ljust(50) + "#{data.leadings}" + "\n\n"
47
- puts "Containing mentions but not directed:".ljust(50) + "#{data.mentions_not_directed}" + "\n\n"
48
- puts "Containing mentions and are replies:".ljust(50) + "#{data.replies}" + "\n\n"
49
- puts "Containing mentions and are not replies:".ljust(50) + "#{data.mentions_not_replies}" + "\n\n"
50
- puts "Containing links:".ljust(50) + "#{data.with_links}" + "\n\n"
51
- puts "Times your posts have been reposted:".ljust(50) + "#{data.reposts}" + "\n\n"
52
- puts "Times your posts have been starred:".ljust(50) + "#{data.stars}" + "\n\n"
53
- puts "Times your posts have been replied:".ljust(50) + "#{data.been_replied}" + "\n\n"
54
- puts "Users you've posted directly to:".ljust(50) + "#{data.directed_users.size}" + "\n\n"
55
- puts "Users you've mentioned:".ljust(50) + "#{data.names.size}" + "\n\n"
56
- puts "You've posted with #{data.clients.size} clients:\n\n#{data.sources.reverse.join(', ')}" + "\n\n"
57
- if options["full"]
58
- puts "Your posted links: #{data.all_links.join(', ')}" + "\n\n"
59
- puts "Users you've posted directly to: #{data.directed_users.reverse.join(', ')}" + "\n\n"
60
- puts "Users you've mentioned: #{data.names.reverse.join(', ')}" + "\n\n"
61
- puts "Your monthly posting frequency:\n\n"
62
- @thor.print_table([["Year", "Month", "Posts\n"]])
63
- puts "------------------"
64
- @thor.print_table(data.freq)
65
- puts "\n"
52
+ if options[:table]
53
+ table = init_table("Your App.net stats")
54
+ table << ["Total posts", data.count]
55
+ table << ["Without mentions", data.without_mentions]
56
+ table << ["Directed to a user", data.leadings]
57
+ table << ["Containing mentions but not directed", data.mentions_not_directed]
58
+ table << ["Containing mentions and are replies", data.replies]
59
+ table << ["Containing mentions and are not replies", data.mentions_not_replies]
60
+ table << ["Containing links", data.with_links]
61
+ table << ["Times your posts have been reposted", data.reposts]
62
+ table << ["Times your posts have been starred", data.stars]
63
+ table << ["Times your posts have been replied", data.been_replied]
64
+ table << ["Users you've posted directly to", data.directed_users.size]
65
+ table << ["Users you've mentioned", data.names.size]
66
+ puts "#{table}\n\n"
67
+ table = init_table("The #{data.clients.size} clients you've posted with")
68
+ data.all_clients.reverse.each do |k,v|
69
+ table << [k,v]
70
+ end
71
+ puts "#{table}\n\n"
72
+ if options["full"]
73
+ puts "- Your posted links:\n"
74
+ data.all_links.each {|link| puts link}
75
+ puts "\n\n"
76
+ table = init_table("Users you've posted directly to")
77
+ data.all_directed.uniq.reverse.each {|k,v| table << ["@#{k}",v]}
78
+ puts "#{table}\n\n"
79
+ table = init_table("Users you've mentioned")
80
+ data.all_mentioned.reverse.each {|k,v| table << ["@#{k}",v]}
81
+ puts "#{table}\n\n"
82
+ table = init_table("Your monthly posting frequency")
83
+ table.headings = ["Year", "Month", "Posts"]
84
+ data.freq.each do |k,v|
85
+ table << [k[0], k[1], v]
86
+ end
87
+ puts "#{table}\n\n"
88
+ end
89
+ else
90
+ puts "Total posts:".ljust(50) + "#{data.count}" + "\n\n"
91
+ puts "Without mentions:".ljust(50) + "#{data.without_mentions}" + "\n\n"
92
+ puts "Directed to a user:".ljust(50) + "#{data.leadings}" + "\n\n"
93
+ puts "Containing mentions but not directed:".ljust(50) + "#{data.mentions_not_directed}" + "\n\n"
94
+ puts "Containing mentions and are replies:".ljust(50) + "#{data.replies}" + "\n\n"
95
+ puts "Containing mentions and are not replies:".ljust(50) + "#{data.mentions_not_replies}" + "\n\n"
96
+ puts "Containing links:".ljust(50) + "#{data.with_links}" + "\n\n"
97
+ puts "Times your posts have been reposted:".ljust(50) + "#{data.reposts}" + "\n\n"
98
+ puts "Times your posts have been starred:".ljust(50) + "#{data.stars}" + "\n\n"
99
+ puts "Times your posts have been replied:".ljust(50) + "#{data.been_replied}" + "\n\n"
100
+ puts "Users you've posted directly to:".ljust(50) + "#{data.directed_users.size}" + "\n\n"
101
+ puts "Users you've mentioned:".ljust(50) + "#{data.names.size}" + "\n\n"
102
+ puts "You've posted with #{data.clients.size} clients:\n\n#{data.sources.reverse.join(', ')}" + "\n\n"
103
+ if options["full"]
104
+ puts "Your posted links: #{data.all_links.join(', ')}" + "\n\n"
105
+ puts "Users you've posted directly to: #{data.directed_users.reverse.join(', ')}" + "\n\n"
106
+ puts "Users you've mentioned: #{data.names.reverse.join(', ')}" + "\n\n"
107
+ puts "Your monthly posting frequency:\n\n"
108
+ @thor.print_table([["Year", "Month", "Posts\n"]])
109
+ puts "------------------"
110
+ @thor.print_table(data.freq)
111
+ puts "\n"
112
+ end
66
113
  end
67
114
  end
68
115
 
@@ -1,3 +1,3 @@
1
1
  module ADNCV
2
- VERSION = "0.4"
2
+ VERSION = "0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adncv
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.4'
4
+ version: '0.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Dejonckheere
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-27 00:00:00.000000000 Z
11
+ date: 2015-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.19'
27
+ - !ruby/object:Gem::Dependency
28
+ name: terminal-table
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.4'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement