accern 3.0.0
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 +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/Guardfile +70 -0
- data/LICENSE.txt +21 -0
- data/README.md +37 -0
- data/Rakefile +6 -0
- data/accern.gemspec +28 -0
- data/bin/console +20 -0
- data/bin/setup +8 -0
- data/exe/accern +4 -0
- data/lib/accern.rb +8 -0
- data/lib/accern/alpha.rb +147 -0
- data/lib/accern/cli.rb +97 -0
- data/lib/accern/flatner.rb +253 -0
- data/lib/accern/version.rb +3 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c0b2c2c71d0eca4b6579e04ff4cf0f43362706d7
|
4
|
+
data.tar.gz: 1b135afac801603e0f34083eb7cfcd431ce74523
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 31936421224235e271cafe80f3307cf5756429dd80fd7025d882e7cc4939ac43704ef8884976595625f347f4294506797d9164482eddddf9d3f7eb4d8a0e7e8c
|
7
|
+
data.tar.gz: 17eea7a7ac38ecebeaa13efa9e3ce2d172adfc326fd7a954ce4053b0bb97d08aae48710fcb26ffcf37493f0161865bd396cfa38b0fcf4aecee34e714cde9e028
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec features) \
|
6
|
+
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
7
|
+
|
8
|
+
## Note: if you are using the `directories` clause above and you are not
|
9
|
+
## watching the project directory ('.'), then you will want to move
|
10
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
11
|
+
#
|
12
|
+
# $ mkdir config
|
13
|
+
# $ mv Guardfile config/
|
14
|
+
# $ ln -s config/Guardfile .
|
15
|
+
#
|
16
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
17
|
+
|
18
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
19
|
+
# rspec may be run, below are examples of the most common uses.
|
20
|
+
# * bundler: 'bundle exec rspec'
|
21
|
+
# * bundler binstubs: 'bin/rspec'
|
22
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
23
|
+
# installed the spring binstubs per the docs)
|
24
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
25
|
+
# * 'just' rspec: 'rspec'
|
26
|
+
|
27
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
28
|
+
require "guard/rspec/dsl"
|
29
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
30
|
+
|
31
|
+
# Feel free to open issues for suggestions and improvements
|
32
|
+
|
33
|
+
# RSpec files
|
34
|
+
rspec = dsl.rspec
|
35
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
36
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
37
|
+
watch(rspec.spec_files)
|
38
|
+
|
39
|
+
# Ruby files
|
40
|
+
ruby = dsl.ruby
|
41
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
42
|
+
|
43
|
+
# Rails files
|
44
|
+
rails = dsl.rails(view_extensions: %w(erb haml slim))
|
45
|
+
dsl.watch_spec_files_for(rails.app_files)
|
46
|
+
dsl.watch_spec_files_for(rails.views)
|
47
|
+
|
48
|
+
watch(rails.controllers) do |m|
|
49
|
+
[
|
50
|
+
rspec.spec.call("routing/#{m[1]}_routing"),
|
51
|
+
rspec.spec.call("controllers/#{m[1]}_controller"),
|
52
|
+
rspec.spec.call("acceptance/#{m[1]}")
|
53
|
+
]
|
54
|
+
end
|
55
|
+
|
56
|
+
# Rails config changes
|
57
|
+
watch(rails.spec_helper) { rspec.spec_dir }
|
58
|
+
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
|
59
|
+
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
|
60
|
+
|
61
|
+
# Capybara features specs
|
62
|
+
watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
|
63
|
+
watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
|
64
|
+
|
65
|
+
# Turnip features and steps
|
66
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
67
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
|
68
|
+
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
|
69
|
+
end
|
70
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Carlos Espejo
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Accern
|
2
|
+
|
3
|
+
A command line interface for the Accern API. Which is used for streaming the realtime data feed.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```shell
|
8
|
+
gem install accern
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
To get started run the `accern` command and follow the prompts.
|
14
|
+
|
15
|
+
```shell
|
16
|
+
$ accern
|
17
|
+
$ Please enter your API Token:
|
18
|
+
$ Your client is now configured and settings saved to ~/.accern.rc.yml.
|
19
|
+
```
|
20
|
+
The the next time you run `accern` the client will begin streaming the full data feed to `./feed.jsonl`
|
21
|
+
|
22
|
+
## Advanced usage
|
23
|
+
|
24
|
+
To reset and bring up the getting started prompts run:
|
25
|
+
|
26
|
+
```shell
|
27
|
+
accern --init
|
28
|
+
```
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
1. Create an issue and describe your idea
|
33
|
+
2. Fork it
|
34
|
+
3. Create your feature branch (`git checkout -b my-new-feature`)
|
35
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
36
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
37
|
+
6. Create new Pull Request
|
data/Rakefile
ADDED
data/accern.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'accern/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'accern'
|
8
|
+
spec.version = Accern::VERSION
|
9
|
+
spec.authors = ['Carlos Espejo']
|
10
|
+
spec.email = ['vendors@accern.com']
|
11
|
+
spec.summary = 'A command line interface for the Accern API.'
|
12
|
+
spec.homepage = 'https://github.com/Accern/accern'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
spec.required_ruby_version = '>= 2.0'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
26
|
+
spec.add_development_dependency 'pry', '~> 0.10'
|
27
|
+
spec.add_development_dependency 'guard-rspec', '~> 4.7'
|
28
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'accern'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
require 'pry'
|
11
|
+
|
12
|
+
# require "irb"
|
13
|
+
# IRB.start(__FILE__)
|
14
|
+
|
15
|
+
args = ['-h']
|
16
|
+
args = []
|
17
|
+
|
18
|
+
c = Accern::Cli.new(args: args)
|
19
|
+
|
20
|
+
binding.pry
|
data/bin/setup
ADDED
data/exe/accern
ADDED
data/lib/accern.rb
ADDED
data/lib/accern/alpha.rb
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
module Accern
|
2
|
+
class Alpha
|
3
|
+
attr_reader :token, :base_url, :uri, :last_id, :new_id, :docs,
|
4
|
+
:format, :flat, :params
|
5
|
+
|
6
|
+
def initialize(options)
|
7
|
+
@token = options.fetch(:token)
|
8
|
+
@format = options.fetch(:format, :json)
|
9
|
+
@params = options.fetch(:params, {})
|
10
|
+
@base_url = 'http://feed.accern.com/v3/alphas'
|
11
|
+
@uri = URI(base_url)
|
12
|
+
read_last_id
|
13
|
+
@flat = Flatner.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def download(path)
|
17
|
+
uri.query = URI.encode_www_form(last_id: last_id) if last_id
|
18
|
+
puts uri
|
19
|
+
|
20
|
+
format_response(
|
21
|
+
Net::HTTP.new(uri.host, uri.port).request_get(uri, header)
|
22
|
+
)
|
23
|
+
|
24
|
+
return if new_id == last_id
|
25
|
+
|
26
|
+
save_last_id
|
27
|
+
|
28
|
+
generate_csv_header(path) if format == :csv
|
29
|
+
|
30
|
+
File.open(path, 'a') do |f|
|
31
|
+
if format == :json
|
32
|
+
docs.reverse_each { |d| f.puts d.to_json }
|
33
|
+
end
|
34
|
+
|
35
|
+
if format == :csv
|
36
|
+
docs.reverse_each { |d| f.puts flat.process(d) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
rescue => e
|
41
|
+
puts e.message
|
42
|
+
puts e.backtrace
|
43
|
+
end
|
44
|
+
|
45
|
+
def download_loop(path)
|
46
|
+
loop do
|
47
|
+
download(path)
|
48
|
+
sleep 8
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def header
|
55
|
+
{ 'Authorization' => %(Token token="#{token}") }
|
56
|
+
end
|
57
|
+
|
58
|
+
def save_last_id
|
59
|
+
@last_id = docs.first['id']
|
60
|
+
File.write('./alpha_last_id.yml', last_id.to_yaml)
|
61
|
+
end
|
62
|
+
|
63
|
+
def format_response(response)
|
64
|
+
@docs = JSON.parse(response.body)
|
65
|
+
@new_id = docs.first.to_h.fetch('id', last_id)
|
66
|
+
end
|
67
|
+
|
68
|
+
def read_last_id
|
69
|
+
if File.exists?('./alpha_last_id.yml')
|
70
|
+
@last_id = YAML.load_file('./alpha_last_id.yml')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def generate_csv_header(path)
|
75
|
+
unless File.exists?(path)
|
76
|
+
File.open(path, 'a') { |f| f.puts csv_header }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def csv_header
|
81
|
+
%w(
|
82
|
+
article_id
|
83
|
+
story_id
|
84
|
+
harvested_at
|
85
|
+
entities_name_1
|
86
|
+
entities_ticker_1
|
87
|
+
entities_global_id_1
|
88
|
+
entities_entity_id_1
|
89
|
+
entities_type_1
|
90
|
+
entities_exchange_1
|
91
|
+
entities_sector_1
|
92
|
+
entities_industry_1
|
93
|
+
entities_country_1
|
94
|
+
entities_region_1
|
95
|
+
entities_index_1
|
96
|
+
entities_competitors_1
|
97
|
+
entities_name_2
|
98
|
+
entities_ticker_2
|
99
|
+
entities_global_id_2
|
100
|
+
entities_entity_id_2
|
101
|
+
entities_type_2
|
102
|
+
entities_exchange_2
|
103
|
+
entities_sector_2
|
104
|
+
entities_industry_2
|
105
|
+
entities_country_2
|
106
|
+
entities_region_2
|
107
|
+
entities_index_2
|
108
|
+
entities_competitors_2
|
109
|
+
event_groups_group_1
|
110
|
+
event_groups_type_1
|
111
|
+
event_groups_group_2
|
112
|
+
event_groups_type_2
|
113
|
+
story_sentiment
|
114
|
+
story_saturation
|
115
|
+
story_volume
|
116
|
+
story_traffic
|
117
|
+
story_shares
|
118
|
+
first_mention
|
119
|
+
article_type
|
120
|
+
article_sentiment
|
121
|
+
article_traffic
|
122
|
+
source_id
|
123
|
+
overall_source_rank
|
124
|
+
event_source_rank_1
|
125
|
+
event_source_rank_2
|
126
|
+
author_id
|
127
|
+
overall_author_rank
|
128
|
+
event_author_rank_1
|
129
|
+
event_author_rank_2
|
130
|
+
event_impact_score_overall
|
131
|
+
event_impact_score_entity_1
|
132
|
+
event_impact_score_entity_2
|
133
|
+
avg_day_sentiment_1
|
134
|
+
avg_day_sentiment_2
|
135
|
+
correlations_max_positive_ticker_1
|
136
|
+
correlations_max_positive_value_1
|
137
|
+
correlations_max_negative_ticker_1
|
138
|
+
correlations_max_negative_value_1
|
139
|
+
correlations_max_positive_ticker_2
|
140
|
+
correlations_max_positive_value_2
|
141
|
+
correlations_max_negative_ticker_2
|
142
|
+
correlations_max_negative_value_2
|
143
|
+
article_url
|
144
|
+
).join(',')
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
data/lib/accern/cli.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
module Accern
|
2
|
+
class Cli
|
3
|
+
attr_reader :stdout, :stdin, :token, :filetype, :valid_types, :config_path,
|
4
|
+
:options, :args, :feed
|
5
|
+
|
6
|
+
def initialize(stdout: $stdout, stdin: $stdin, args: [], feed: Alpha)
|
7
|
+
@stdout = stdout
|
8
|
+
@stdin = stdin
|
9
|
+
@args = args
|
10
|
+
@options = {}
|
11
|
+
@filetype = 'json'
|
12
|
+
@valid_types = %w(json csv)
|
13
|
+
@config_path = "#{ENV['HOME']}/.accern.rc.yml"
|
14
|
+
@feed = feed
|
15
|
+
end
|
16
|
+
|
17
|
+
def start
|
18
|
+
load_config
|
19
|
+
parse_options
|
20
|
+
|
21
|
+
if options[:init]
|
22
|
+
ask_for_info
|
23
|
+
else
|
24
|
+
feed.new(token: token, format: filetype.to_sym)
|
25
|
+
.download_loop('./feed.jsonl')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def ask_for_token
|
30
|
+
ask_question('Please enter your API Token: ', :token)
|
31
|
+
end
|
32
|
+
|
33
|
+
def ask_for_filetype
|
34
|
+
ask_question('Please enter the file type (JSON or CSV): ', :filetype)
|
35
|
+
valid_filetype?
|
36
|
+
end
|
37
|
+
|
38
|
+
def load_config
|
39
|
+
if File.exist?(config_path)
|
40
|
+
config = YAML.load_file(config_path)
|
41
|
+
@token = config[:token]
|
42
|
+
@filetype = config[:filetype]
|
43
|
+
else
|
44
|
+
ask_for_info
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def parse_options
|
49
|
+
parser = OptionParser.new do |opts|
|
50
|
+
opts.banner = 'A command line interface for the Accern API'
|
51
|
+
|
52
|
+
opts.on('--init', 'Display the getting started prompts.') do
|
53
|
+
options[:init] = true
|
54
|
+
end
|
55
|
+
|
56
|
+
opts.on('--version', 'Show version') do
|
57
|
+
options[:version] = Accern::VERSION
|
58
|
+
puts Accern::VERSION
|
59
|
+
exit
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
parser.parse!(args)
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def ask_for_info
|
69
|
+
ask_for_token
|
70
|
+
# ask_for_filetype
|
71
|
+
save_config
|
72
|
+
end
|
73
|
+
|
74
|
+
def ask_question(text, field)
|
75
|
+
stdout.print text
|
76
|
+
instance_variable_set(
|
77
|
+
"@#{field}", stdin.gets.to_s.chomp.downcase.delete('.', '')
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
81
|
+
def valid_filetype?
|
82
|
+
return if valid_types.include?(filetype)
|
83
|
+
stdout.puts 'Invalid file type, defaulting to JSON'
|
84
|
+
@filetype = 'json'
|
85
|
+
end
|
86
|
+
|
87
|
+
def save_config
|
88
|
+
config = {
|
89
|
+
token: token,
|
90
|
+
filetype: filetype
|
91
|
+
}
|
92
|
+
|
93
|
+
File.write(config_path, config.to_yaml)
|
94
|
+
stdout.puts 'Your client is now configured and settings saved to ~/.accern.rc.yml.'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,253 @@
|
|
1
|
+
module Accern
|
2
|
+
class Flatner
|
3
|
+
def process(x)
|
4
|
+
article_id = x['article_id']
|
5
|
+
story_id = x['story_id']
|
6
|
+
harvested_at = x['harvested_at']
|
7
|
+
delivered_at = x['delivered_at']
|
8
|
+
|
9
|
+
entities_name_1 = x['entities'].first['name'].to_s.tr(',', ' ')
|
10
|
+
entities_ticker_1 = x['entities'].first['ticker'].to_s.tr(',', ' ')
|
11
|
+
|
12
|
+
if x['entities'].first['global_id'].nil?
|
13
|
+
x['entities'].first['global_id'] = []
|
14
|
+
end
|
15
|
+
if x['entities'].first['entity_id'].nil?
|
16
|
+
x['entities'].first['entity_id'] = []
|
17
|
+
end
|
18
|
+
|
19
|
+
entities_global_id_1 = x['entities'].first['global_id']
|
20
|
+
.join(' ').to_s.tr(',', ' ')
|
21
|
+
|
22
|
+
entities_entity_id_1 = x['entities'].first['entity_id']
|
23
|
+
.join(' ').to_s.tr(',', ' ')
|
24
|
+
|
25
|
+
entities_type_1 = x['entities'].first['type'].to_s.tr(',', ' ')
|
26
|
+
entities_exchange_1 = x['entities'].first['exchange'].to_s.tr(',', ' ')
|
27
|
+
entities_sector_1 = x['entities'].first['sector'].to_s.tr(',', ' ')
|
28
|
+
entities_industry_1 = x['entities'].first['industry'].to_s.tr(',', ' ')
|
29
|
+
entities_country_1 = x['entities'].first['country'].to_s.tr(',', ' ')
|
30
|
+
entities_region_1 = x['entities'].first['region'].to_s.tr(',', ' ')
|
31
|
+
entities_index_1 = x['entities'].first['index'].to_s.tr(',', ' ')
|
32
|
+
entities_competitors_1 = x['entities'].first['competitors']
|
33
|
+
.to_s.tr(',', ' ')
|
34
|
+
|
35
|
+
entities_name_2 = ''
|
36
|
+
entities_ticker_2 = ''
|
37
|
+
entities_global_id_2 = ''
|
38
|
+
entities_entity_id_2 = ''
|
39
|
+
entities_type_2 = ''
|
40
|
+
entities_exchange_2 = ''
|
41
|
+
entities_sector_2 = ''
|
42
|
+
entities_industry_2 = ''
|
43
|
+
entities_country_2 = ''
|
44
|
+
entities_region_2 = ''
|
45
|
+
entities_index_2 = ''
|
46
|
+
entities_competitors_2 = ''
|
47
|
+
|
48
|
+
if x['entities'].length > 1
|
49
|
+
entities_name_2 = x['entities'][1]['name'].to_s.tr(',', ' ')
|
50
|
+
entities_ticker_2 = x['entities'][1]['ticker'].to_s.tr(',', ' ')
|
51
|
+
if x['entities'][1]['global_id'].nil?
|
52
|
+
x['entities'][1]['global_id'] = []
|
53
|
+
end
|
54
|
+
if x['entities'][1]['entity_id'].nil?
|
55
|
+
x['entities'][1]['entity_id'] = []
|
56
|
+
end
|
57
|
+
|
58
|
+
entities_global_id_2 = x['entities'][1]['global_id']
|
59
|
+
.join(' ').to_s.tr(',', ' ')
|
60
|
+
|
61
|
+
entities_entity_id_2 = x['entities'][1]['entity_id']
|
62
|
+
.join(' ').to_s.tr(',', ' ')
|
63
|
+
|
64
|
+
entities_type_2 = x['entities'][1]['type'].to_s.tr(',', ' ')
|
65
|
+
entities_exchange_2 = x['entities'][1]['exchange'].to_s.tr(',', ' ')
|
66
|
+
entities_sector_2 = x['entities'][1]['sector'].to_s.tr(',', ' ')
|
67
|
+
entities_industry_2 = x['entities'][1]['industry'].to_s.tr(',', ' ')
|
68
|
+
entities_country_2 = x['entities'][1]['country'].to_s.tr(',', ' ')
|
69
|
+
entities_region_2 = x['entities'][1]['region'].to_s.tr(',', ' ')
|
70
|
+
entities_index_2 = x['entities'][1]['index'].to_s.tr(',', ' ')
|
71
|
+
entities_competitors_2 = x['entities'][1]['competitors'].to_s.tr(',', ' ')
|
72
|
+
end
|
73
|
+
|
74
|
+
event_groups_group_1 = x['event_groups'].first['group'].to_s.tr(',', ' ')
|
75
|
+
event_groups_type_1 = x['event_groups'].first['type'].to_s.tr(',', ' ')
|
76
|
+
event_groups_group_2 = ''
|
77
|
+
event_groups_type_2 = ''
|
78
|
+
|
79
|
+
if x['event_groups'].length > 1
|
80
|
+
event_groups_group_2 = x['event_groups'][1]['group'].to_s.tr(',', ' ')
|
81
|
+
event_groups_type_2 = x['event_groups'][1]['type'].to_s.tr(',', ' ')
|
82
|
+
end
|
83
|
+
|
84
|
+
story_sentiment = x['story_sentiment']
|
85
|
+
story_saturation = x['story_saturation']
|
86
|
+
story_volume = x['story_volume']
|
87
|
+
story_traffic = x['story_traffic']
|
88
|
+
story_shares = x['story_shares']
|
89
|
+
first_mention = x['first_mention']
|
90
|
+
article_type = x['article_type']
|
91
|
+
article_sentiment = x['article_sentiment']
|
92
|
+
article_traffic = x['article_traffic']
|
93
|
+
article_url = x['article_url']
|
94
|
+
|
95
|
+
if article_url.nil?
|
96
|
+
article_url = ''
|
97
|
+
end
|
98
|
+
|
99
|
+
article_url = article_url.to_s.tr(',', '')
|
100
|
+
|
101
|
+
author_id = x['author_id']
|
102
|
+
source_id = x['source_id']
|
103
|
+
|
104
|
+
overall_source_rank = x['overall_source_rank']
|
105
|
+
event_source_rank_1 = ''
|
106
|
+
if x['event_source_rank'].length > 0
|
107
|
+
event_source_rank_1 = x['event_source_rank'].first['source_rank']
|
108
|
+
end
|
109
|
+
event_source_rank_2 = ''
|
110
|
+
if x['event_source_rank'].length > 1
|
111
|
+
event_source_rank_2 = x['event_source_rank'][1]['source_rank']
|
112
|
+
end
|
113
|
+
|
114
|
+
overall_author_rank = x['overall_author_rank']
|
115
|
+
event_author_rank_1 = ''
|
116
|
+
if x['event_author_rank'].length > 0
|
117
|
+
event_author_rank_1 = x['event_author_rank'].first['author_rank']
|
118
|
+
end
|
119
|
+
event_author_rank_2 = ''
|
120
|
+
if x['event_author_rank'].length > 1
|
121
|
+
event_author_rank_2 = x['event_author_rank'][1]['author_rank']
|
122
|
+
end
|
123
|
+
|
124
|
+
event_impact_score_overall = x['event_impact_score']['overall']
|
125
|
+
event_impact_score_entity_1 = ''
|
126
|
+
event_impact_score_entity_2 = ''
|
127
|
+
|
128
|
+
event_impact_score_entity_1 = x['event_impact_score']['on_entities']
|
129
|
+
.first['on_entity']
|
130
|
+
|
131
|
+
if x['event_impact_score']['on_entities'].length > 1
|
132
|
+
event_impact_score_entity_2 =
|
133
|
+
x['event_impact_score']['on_entities'][1]['on_entity']
|
134
|
+
end
|
135
|
+
|
136
|
+
avg_day_sentiment_1 = ''
|
137
|
+
avg_day_sentiment_2 = ''
|
138
|
+
if x['avg_day_sentiment'].nil?
|
139
|
+
x['avg_day_sentiment'] = []
|
140
|
+
end
|
141
|
+
if x['avg_day_sentiment_1'] && x['avg_day_sentiment_1'].length > 0
|
142
|
+
avg_day_sentiment_1 = x['avg_day_sentiment_1'].first['value']
|
143
|
+
end
|
144
|
+
if x['avg_day_sentiment_1'] && x['avg_day_sentiment_1'].length > 1
|
145
|
+
avg_day_sentiment_2 = x['avg_day_sentiment_1'][1]['value']
|
146
|
+
end
|
147
|
+
|
148
|
+
correlations_max_positive_ticker_1 = ''
|
149
|
+
correlations_max_positive_value_1 = ''
|
150
|
+
correlations_max_negative_ticker_1 = ''
|
151
|
+
correlations_max_negative_value_1 = ''
|
152
|
+
correlations_max_positive_ticker_2 = ''
|
153
|
+
correlations_max_positive_value_2 = ''
|
154
|
+
correlations_max_negative_ticker_2 = ''
|
155
|
+
correlations_max_negative_value_2 = ''
|
156
|
+
|
157
|
+
if x['correlations'].length > 0
|
158
|
+
cors = x['correlations'].first['with_entity']
|
159
|
+
cors.each do |c|
|
160
|
+
if c['type'] == 'max_positive'
|
161
|
+
correlations_max_positive_ticker_1 = c['ticker'].to_s.tr(',', ' ')
|
162
|
+
correlations_max_positive_value_1 = c['value']
|
163
|
+
else
|
164
|
+
correlations_max_negative_ticker_1 = c['ticker'].to_s.tr(',', ' ')
|
165
|
+
correlations_max_negative_value_1 = c['value']
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
if x['correlations'].length > 1
|
171
|
+
cors = x['correlations'][1]['with_entity']
|
172
|
+
cors.each do |c|
|
173
|
+
if c['type'] == 'max_positive'
|
174
|
+
correlations_max_positive_ticker_2 = c['ticker'].to_s.tr(',', ' ')
|
175
|
+
correlations_max_positive_value_2 = c['value']
|
176
|
+
else
|
177
|
+
correlations_max_negative_ticker_2 = c['ticker'].to_s.tr(',', ' ')
|
178
|
+
correlations_max_negative_value_2 = c['value']
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
[
|
184
|
+
article_id,
|
185
|
+
story_id,
|
186
|
+
harvested_at,
|
187
|
+
entities_name_1,
|
188
|
+
entities_ticker_1,
|
189
|
+
entities_global_id_1,
|
190
|
+
entities_entity_id_1,
|
191
|
+
entities_type_1,
|
192
|
+
entities_exchange_1,
|
193
|
+
entities_sector_1,
|
194
|
+
entities_industry_1,
|
195
|
+
entities_country_1,
|
196
|
+
entities_region_1,
|
197
|
+
entities_index_1,
|
198
|
+
entities_competitors_1,
|
199
|
+
entities_name_2,
|
200
|
+
entities_ticker_2,
|
201
|
+
entities_global_id_2,
|
202
|
+
entities_entity_id_2,
|
203
|
+
entities_type_2,
|
204
|
+
entities_exchange_2,
|
205
|
+
entities_sector_2,
|
206
|
+
entities_industry_2,
|
207
|
+
entities_country_2,
|
208
|
+
entities_region_2,
|
209
|
+
entities_index_2,
|
210
|
+
entities_competitors_2,
|
211
|
+
event_groups_group_1,
|
212
|
+
event_groups_type_1,
|
213
|
+
event_groups_group_2,
|
214
|
+
event_groups_type_2,
|
215
|
+
story_sentiment,
|
216
|
+
story_saturation,
|
217
|
+
story_volume,
|
218
|
+
story_traffic,
|
219
|
+
story_shares,
|
220
|
+
first_mention,
|
221
|
+
article_type,
|
222
|
+
article_sentiment,
|
223
|
+
article_traffic,
|
224
|
+
source_id,
|
225
|
+
overall_source_rank,
|
226
|
+
event_source_rank_1,
|
227
|
+
event_source_rank_2,
|
228
|
+
author_id,
|
229
|
+
overall_author_rank,
|
230
|
+
event_author_rank_1,
|
231
|
+
event_author_rank_2,
|
232
|
+
event_impact_score_overall,
|
233
|
+
event_impact_score_entity_1,
|
234
|
+
event_impact_score_entity_2,
|
235
|
+
avg_day_sentiment_1,
|
236
|
+
avg_day_sentiment_2,
|
237
|
+
correlations_max_positive_ticker_1,
|
238
|
+
correlations_max_positive_value_1,
|
239
|
+
correlations_max_negative_ticker_1,
|
240
|
+
correlations_max_negative_value_1,
|
241
|
+
correlations_max_positive_ticker_2,
|
242
|
+
correlations_max_positive_value_2,
|
243
|
+
correlations_max_negative_ticker_2,
|
244
|
+
correlations_max_negative_value_2,
|
245
|
+
"\"#{article_url}\""
|
246
|
+
].join(',')
|
247
|
+
|
248
|
+
rescue => e
|
249
|
+
puts e
|
250
|
+
puts e.backtrace
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: accern
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 3.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Carlos Espejo
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.10'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '4.7'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '4.7'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- vendors@accern.com
|
86
|
+
executables:
|
87
|
+
- accern
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- Guardfile
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- accern.gemspec
|
100
|
+
- bin/console
|
101
|
+
- bin/setup
|
102
|
+
- exe/accern
|
103
|
+
- lib/accern.rb
|
104
|
+
- lib/accern/alpha.rb
|
105
|
+
- lib/accern/cli.rb
|
106
|
+
- lib/accern/flatner.rb
|
107
|
+
- lib/accern/version.rb
|
108
|
+
homepage: https://github.com/Accern/accern
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '2.0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.5.2
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: A command line interface for the Accern API.
|
132
|
+
test_files: []
|