andeltsa 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +2 -0
- data/andeltsa.gemspec +36 -0
- data/api_key.txt +1 -0
- data/bin/andeltsa +71 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/.rubocop.yml +235 -0
- data/lib/alchemy_connect.rb +22 -0
- data/lib/andeltsa.rb +35 -0
- data/lib/andeltsa/version.rb +3 -0
- data/lib/connection.rb +67 -0
- data/lib/helper.rb +69 -0
- data/stop_words.yml +1 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c026acf784072321fdcd31c9a3ee579e9b166223
|
4
|
+
data.tar.gz: 2dc0aacf7adc7a8d3f3be42ab3c45d7b24bdb5a9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 85f3317625c32c9b889669b69a1ff9b796eeb3b317c4866d26554803d7c5aaa366235614f60cdf1f6655ab19e70f1d258959b8b7546d8447e6d62439d4ec32e9
|
7
|
+
data.tar.gz: 47460c6cfc2e48db7f21eccc45308080abf19339abe5b7fdb01a63187f0d08ff9b8bac315632da9fc9335f00ba7764309d835188b1b21b598c2286d186241294
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at mubarakadeimam@yahoo.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 mubarakadeimam
|
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,39 @@
|
|
1
|
+
# Andelatsa
|
2
|
+
|
3
|
+
Welcome to ANDELATSA, its a small application developed in Ruby to carry out sentiment analysis, the app is a cli and the interface is quite #sweet. Hence, no time for stories.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'andelatsa'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install andelatsa
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
|
+
|
29
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/andelatsa. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
34
|
+
|
35
|
+
|
36
|
+
## License
|
37
|
+
|
38
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
39
|
+
|
data/Rakefile
ADDED
data/andeltsa.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'andeltsa/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "andeltsa"
|
8
|
+
spec.version = Andeltsa::VERSION
|
9
|
+
spec.authors = "mubarakadeimam"
|
10
|
+
spec.email = "mubarakadeimam@yahoo.com"
|
11
|
+
|
12
|
+
spec.summary = "An Andela Bootcamp Project"
|
13
|
+
spec.description = "Carries out Tweets analysis using Alchemy Sentiment Analysis API"
|
14
|
+
spec.homepage = "https://github.com/mubarakadeimam/TwitterSentimentAnalyzer"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "bin"
|
27
|
+
spec.executables = ["andeltsa"]
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
31
|
+
spec.add_development_dependency "oauth"
|
32
|
+
spec.add_development_dependency "json"
|
33
|
+
spec.add_development_dependency "colorize"
|
34
|
+
spec.add_development_dependency "rubygems"
|
35
|
+
spec.add_development_dependency "date"
|
36
|
+
end
|
data/api_key.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
119e3b6dc0ce828fd17a8a27e6306f2d8326d01c
|
data/bin/andeltsa
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "date"
|
3
|
+
require "colorize"
|
4
|
+
require_relative "../lib/andeltsa"
|
5
|
+
require_relative "../lib/connection"
|
6
|
+
require_relative "../lib/alchemy_connect"
|
7
|
+
|
8
|
+
# The CLI
|
9
|
+
print "+#{'==' * 24}=+".bold.green
|
10
|
+
puts "\n|#{' ' * 6}Welcome to Twitter Sentiment Analyzer#{' ' * 6}|".bold.green
|
11
|
+
puts "|#{' ' * 11}An Andela BootCamp Project#{' ' * 12}|".bold.green
|
12
|
+
puts "|#{' ' * 23}by#{' ' * 24}|".bold.green
|
13
|
+
puts "|#{' ' * 14}Mubarak Adeshina IMAM#{' ' * 14}|".bold.green
|
14
|
+
print "+#{'==' * 24}=+".bold.green
|
15
|
+
puts "\n\n#{' ' * 1}Please wait while we connect to"\
|
16
|
+
" the Twitter API#{' ' * 1}\n".yellow
|
17
|
+
|
18
|
+
response_code = Connection.check_connection
|
19
|
+
|
20
|
+
if response_code == "200"
|
21
|
+
puts "Connection successful"
|
22
|
+
else
|
23
|
+
puts "Connection failed"
|
24
|
+
end
|
25
|
+
|
26
|
+
this_day = Date.today
|
27
|
+
last_week = this_day - 7
|
28
|
+
last_month = this_day - 30
|
29
|
+
|
30
|
+
condition = true
|
31
|
+
while condition
|
32
|
+
print "\nPlease, enter you Twitter Handle: "
|
33
|
+
username = gets.chomp
|
34
|
+
print "\nPlease enter 1 to examine the tweets since last week\n"\
|
35
|
+
"or enter 2 to examine the tweets since last month: "
|
36
|
+
response = gets.chomp.to_i
|
37
|
+
case response
|
38
|
+
when 1
|
39
|
+
since_date = last_week
|
40
|
+
when 2
|
41
|
+
since_date = last_month
|
42
|
+
end
|
43
|
+
|
44
|
+
user = Andeltsa::TwitterRequest.new(username, since_date)
|
45
|
+
Helper.display_ranking(user.words_rank)
|
46
|
+
|
47
|
+
File.delete("full_tweets_#{username}.json")
|
48
|
+
|
49
|
+
print "Do you care for a sentiment analysis of the tweets: Yes/No ? "
|
50
|
+
response = gets.chomp.downcase.split("")[0]
|
51
|
+
case response
|
52
|
+
when "y"
|
53
|
+
tweets = File.read("tweets_only_#{username}.json")
|
54
|
+
File.delete("tweets_only_#{username}.json")
|
55
|
+
puts "\nProcessing tweets for @#{username}"
|
56
|
+
SentimentAnalysis.get_sentiment(tweets)
|
57
|
+
when "n"
|
58
|
+
"Okay, thanks"
|
59
|
+
end
|
60
|
+
print "\nDo you want to exit from the app: Yes/No ? "
|
61
|
+
response = gets.chomp.downcase
|
62
|
+
case response
|
63
|
+
when "yes" || "y"
|
64
|
+
condition = false
|
65
|
+
Helper.exit_message
|
66
|
+
when "no"
|
67
|
+
puts "Okay, now you can continue"
|
68
|
+
else
|
69
|
+
puts "Sorry, I don't get that"
|
70
|
+
end
|
71
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "andeltsa"
|
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
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/.rubocop.yml
ADDED
@@ -0,0 +1,235 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- "vendor/**/*"
|
4
|
+
- "db/schema.rb"
|
5
|
+
- "bin/*"
|
6
|
+
- "config/environments/*"
|
7
|
+
UseCache: false
|
8
|
+
Style/CollectionMethods:
|
9
|
+
Description: Preferred collection methods.
|
10
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
|
11
|
+
Enabled: true
|
12
|
+
PreferredMethods:
|
13
|
+
collect: map
|
14
|
+
collect!: map!
|
15
|
+
find: detect
|
16
|
+
find_all: select
|
17
|
+
reduce: inject
|
18
|
+
Style/DotPosition:
|
19
|
+
Description: Checks the position of the dot in multi-line method calls.
|
20
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains
|
21
|
+
Enabled: true
|
22
|
+
EnforcedStyle: trailing
|
23
|
+
SupportedStyles:
|
24
|
+
- leading
|
25
|
+
- trailing
|
26
|
+
Style/FileName:
|
27
|
+
Description: Use snake_case for source file names.
|
28
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files
|
29
|
+
Enabled: false
|
30
|
+
Exclude: []
|
31
|
+
Style/GuardClause:
|
32
|
+
Description: Check for conditionals that can be replaced with guard clauses
|
33
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals
|
34
|
+
Enabled: false
|
35
|
+
MinBodyLength: 1
|
36
|
+
Style/IfUnlessModifier:
|
37
|
+
Description: Favor modifier if/unless usage when you have a single-line body.
|
38
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier
|
39
|
+
Enabled: false
|
40
|
+
MaxLineLength: 80
|
41
|
+
Style/OptionHash:
|
42
|
+
Description: Don't use option hashes when you can use keyword arguments.
|
43
|
+
Enabled: false
|
44
|
+
Style/PercentLiteralDelimiters:
|
45
|
+
Description: Use `%`-literal delimiters consistently
|
46
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces
|
47
|
+
Enabled: false
|
48
|
+
PreferredDelimiters:
|
49
|
+
"%": "()"
|
50
|
+
"%i": "()"
|
51
|
+
"%q": "()"
|
52
|
+
"%Q": "()"
|
53
|
+
"%r": "{}"
|
54
|
+
"%s": "()"
|
55
|
+
"%w": "()"
|
56
|
+
"%W": "()"
|
57
|
+
"%x": "()"
|
58
|
+
Style/PredicateName:
|
59
|
+
Description: Check the names of predicate methods.
|
60
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark
|
61
|
+
Enabled: true
|
62
|
+
NamePrefix:
|
63
|
+
- is_
|
64
|
+
- has_
|
65
|
+
- have_
|
66
|
+
NamePrefixBlacklist:
|
67
|
+
- is_
|
68
|
+
Exclude:
|
69
|
+
- spec/**/*
|
70
|
+
Style/RaiseArgs:
|
71
|
+
Description: Checks the arguments passed to raise/fail.
|
72
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages
|
73
|
+
Enabled: false
|
74
|
+
EnforcedStyle: exploded
|
75
|
+
SupportedStyles:
|
76
|
+
- compact
|
77
|
+
- exploded
|
78
|
+
Style/SignalException:
|
79
|
+
Description: Checks for proper usage of fail and raise.
|
80
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method
|
81
|
+
Enabled: false
|
82
|
+
EnforcedStyle: semantic
|
83
|
+
SupportedStyles:
|
84
|
+
- only_raise
|
85
|
+
- only_fail
|
86
|
+
- semantic
|
87
|
+
Style/SingleLineBlockParams:
|
88
|
+
Description: Enforces the names of some block params.
|
89
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks
|
90
|
+
Enabled: false
|
91
|
+
Methods:
|
92
|
+
- reduce:
|
93
|
+
- a
|
94
|
+
- e
|
95
|
+
- inject:
|
96
|
+
- a
|
97
|
+
- e
|
98
|
+
Style/SingleLineMethods:
|
99
|
+
Description: Avoid single-line methods.
|
100
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods
|
101
|
+
Enabled: false
|
102
|
+
AllowIfMethodIsEmpty: true
|
103
|
+
Style/StringLiterals:
|
104
|
+
Description: Checks if uses of quotes match the configured preference.
|
105
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals
|
106
|
+
Enabled: true
|
107
|
+
EnforcedStyle: double_quotes
|
108
|
+
SupportedStyles:
|
109
|
+
- single_quotes
|
110
|
+
- double_quotes
|
111
|
+
Style/StringLiteralsInInterpolation:
|
112
|
+
Description: Checks if uses of quotes inside expressions in interpolated strings
|
113
|
+
match the configured preference.
|
114
|
+
Enabled: true
|
115
|
+
EnforcedStyle: single_quotes
|
116
|
+
SupportedStyles:
|
117
|
+
- single_quotes
|
118
|
+
- double_quotes
|
119
|
+
Style/TrailingCommaInLiteral:
|
120
|
+
Description: Checks for trailing comma in parameter lists and literals.
|
121
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas
|
122
|
+
Enabled: false
|
123
|
+
EnforcedStyleForMultiline: no_comma
|
124
|
+
SupportedStyles:
|
125
|
+
- comma
|
126
|
+
- no_comma
|
127
|
+
Metrics/AbcSize:
|
128
|
+
Description: A calculated magnitude based on number of assignments, branches, and
|
129
|
+
conditions.
|
130
|
+
Enabled: false
|
131
|
+
Max: 15
|
132
|
+
Metrics/ClassLength:
|
133
|
+
Description: Avoid classes longer than 100 lines of code.
|
134
|
+
Enabled: false
|
135
|
+
CountComments: false
|
136
|
+
Max: 100
|
137
|
+
Metrics/ModuleLength:
|
138
|
+
CountComments: false
|
139
|
+
Max: 100
|
140
|
+
Description: Avoid modules longer than 100 lines of code.
|
141
|
+
Enabled: false
|
142
|
+
Metrics/CyclomaticComplexity:
|
143
|
+
Description: A complexity metric that is strongly correlated to the number of test
|
144
|
+
cases needed to validate a method.
|
145
|
+
Enabled: false
|
146
|
+
Max: 6
|
147
|
+
Metrics/MethodLength:
|
148
|
+
Description: Avoid methods longer than 10 lines of code.
|
149
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
|
150
|
+
Enabled: false
|
151
|
+
CountComments: false
|
152
|
+
Max: 10
|
153
|
+
Metrics/ParameterLists:
|
154
|
+
Description: Avoid parameter lists longer than three or four parameters.
|
155
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params
|
156
|
+
Enabled: false
|
157
|
+
Max: 5
|
158
|
+
CountKeywordArgs: true
|
159
|
+
Metrics/PerceivedComplexity:
|
160
|
+
Description: A complexity metric geared towards measuring complexity for a human
|
161
|
+
reader.
|
162
|
+
Enabled: false
|
163
|
+
Max: 7
|
164
|
+
Lint/AssignmentInCondition:
|
165
|
+
Description: Don't use assignment in conditions.
|
166
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition
|
167
|
+
Enabled: false
|
168
|
+
AllowSafeAssignment: true
|
169
|
+
Style/InlineComment:
|
170
|
+
Description: Avoid inline comments.
|
171
|
+
Enabled: false
|
172
|
+
Style/AccessorMethodName:
|
173
|
+
Description: Check the naming of accessor methods for get_/set_.
|
174
|
+
Enabled: false
|
175
|
+
Style/Alias:
|
176
|
+
Description: Use alias_method instead of alias.
|
177
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method
|
178
|
+
Enabled: false
|
179
|
+
Style/Documentation:
|
180
|
+
Description: Document classes and non-namespace modules.
|
181
|
+
Enabled: false
|
182
|
+
Style/DoubleNegation:
|
183
|
+
Description: Checks for uses of double negation (!!).
|
184
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang
|
185
|
+
Enabled: false
|
186
|
+
Style/EachWithObject:
|
187
|
+
Description: Prefer `each_with_object` over `inject` or `reduce`.
|
188
|
+
Enabled: false
|
189
|
+
Style/EmptyLiteral:
|
190
|
+
Description: Prefer literals to Array.new/Hash.new/String.new.
|
191
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash
|
192
|
+
Enabled: false
|
193
|
+
Style/ModuleFunction:
|
194
|
+
Description: Checks for usage of `extend self` in modules.
|
195
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function
|
196
|
+
Enabled: false
|
197
|
+
Style/OneLineConditional:
|
198
|
+
Description: Favor the ternary operator(?:) over if/then/else/end constructs.
|
199
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator
|
200
|
+
Enabled: false
|
201
|
+
Style/PerlBackrefs:
|
202
|
+
Description: Avoid Perl-style regex back references.
|
203
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers
|
204
|
+
Enabled: false
|
205
|
+
Style/Send:
|
206
|
+
Description: Prefer `Object#__send__` or `Object#public_send` to `send`, as `send`
|
207
|
+
may overlap with existing methods.
|
208
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#prefer-public-send
|
209
|
+
Enabled: false
|
210
|
+
Style/SpecialGlobalVars:
|
211
|
+
Description: Avoid Perl-style global variables.
|
212
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms
|
213
|
+
Enabled: false
|
214
|
+
Style/VariableInterpolation:
|
215
|
+
Description: Don't interpolate global, instance and class variables directly in
|
216
|
+
strings.
|
217
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate
|
218
|
+
Enabled: false
|
219
|
+
Style/WhenThen:
|
220
|
+
Description: Use when x then ... for one-line cases.
|
221
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases
|
222
|
+
Enabled: false
|
223
|
+
Lint/EachWithObjectArgument:
|
224
|
+
Description: Check for immutable argument given to each_with_object.
|
225
|
+
Enabled: true
|
226
|
+
Lint/HandleExceptions:
|
227
|
+
Description: Don't suppress exception.
|
228
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions
|
229
|
+
Enabled: false
|
230
|
+
Lint/LiteralInCondition:
|
231
|
+
Description: Checks of literals used in conditions.
|
232
|
+
Enabled: false
|
233
|
+
Lint/LiteralInInterpolation:
|
234
|
+
Description: Checks for literals used in interpolation.
|
235
|
+
Enabled: false
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "././alchemyapi_ruby/alchemyapi"
|
2
|
+
|
3
|
+
module SentimentAnalysis
|
4
|
+
def self.get_sentiment(tweets)
|
5
|
+
alchemyapi = AlchemyAPI.new
|
6
|
+
response = alchemyapi.sentiment("text", tweets)
|
7
|
+
|
8
|
+
if response["status"] == "OK"
|
9
|
+
puts '## Response Object ##'
|
10
|
+
puts JSON.pretty_generate(response)
|
11
|
+
puts ""
|
12
|
+
puts '## Document Sentiment ##'
|
13
|
+
puts "type: " + response["docSentiment"]["type"]
|
14
|
+
# Make sure score exists (it's not returned for neutral sentiment
|
15
|
+
if response["docSentiment"].key?("score")
|
16
|
+
puts "score: " + response["docSentiment"]["score"]
|
17
|
+
end
|
18
|
+
else
|
19
|
+
puts "Error in sentiment analysis call: " + response["statusInfo"]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/andeltsa.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "oauth"
|
3
|
+
require "date"
|
4
|
+
require_relative "./connection"
|
5
|
+
require_relative "./helper"
|
6
|
+
require_relative "andeltsa/version"
|
7
|
+
|
8
|
+
module Andeltsa
|
9
|
+
# Your code goes here...
|
10
|
+
class TwitterRequest
|
11
|
+
include Helper, Connection
|
12
|
+
attr_accessor :username, :date, :tweets_words, :okay_words, :words_rank
|
13
|
+
def initialize(username, date)
|
14
|
+
@username = username
|
15
|
+
@date = date
|
16
|
+
@tweets_words = tweet_collect
|
17
|
+
@okay_words = Helper.remove_stop_words(tweets_words)
|
18
|
+
@words_rank = Helper.rank_words(okay_words)
|
19
|
+
end
|
20
|
+
|
21
|
+
def tweet_collect
|
22
|
+
Connection.tweets_request(username, date)
|
23
|
+
tweets_only = File.open("./tweets_only_#{username}.json", "r")
|
24
|
+
tweets_words = []
|
25
|
+
tweets_only.each do |tweet|
|
26
|
+
tweets_words << tweet
|
27
|
+
end
|
28
|
+
tweets_words.join(" ").split(/[^a-zA-Z]/)
|
29
|
+
end
|
30
|
+
|
31
|
+
def count_words_in_tweet
|
32
|
+
Helper.words_counter
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/connection.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "oauth"
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
module Connection
|
6
|
+
# Change the following values to those provided on dev.twitter.com
|
7
|
+
# The consumer key identifies the application making the request.
|
8
|
+
# The access token identifies the user making the request.
|
9
|
+
@consumer_key = OAuth::Consumer.new(
|
10
|
+
"vyD8Kjp2fP05sUXUjWgpW2Iu2",
|
11
|
+
"u6tFDV9TQwuLS4pR30NrD5ncHfg2SvozLjCFjUnyVFsE69RBkV")
|
12
|
+
@access_token = OAuth::Token.new(
|
13
|
+
"212657683-Ln1rsRDKydHEqcHgl9coIKxzAF7duyEkThJJDx8F",
|
14
|
+
"hNxJPcQj0GF1yyjrlvFqFz7fjli8T7KAJA8XqHRmuehiP")
|
15
|
+
|
16
|
+
# All requests will be sent to this server.
|
17
|
+
@base_url = "https://api.twitter.com"
|
18
|
+
|
19
|
+
# The verify credentials endpoint returns a 200 status if
|
20
|
+
# the request is signed correctly.
|
21
|
+
def self.check_connection
|
22
|
+
address = URI("#{@base_url}/1.1/account/verify_credentials.json")
|
23
|
+
# Set up Net::HTTP to use SSL, which is required by Twitter.
|
24
|
+
http = Net::HTTP.new address.host, address.port
|
25
|
+
http.use_ssl = true
|
26
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
27
|
+
# Build the request and authorize it with OAuth.
|
28
|
+
request = Net::HTTP::Get.new address.request_uri
|
29
|
+
request.oauth! http, @consumer_key, @access_token
|
30
|
+
# Issue the request and return the response.
|
31
|
+
http.start
|
32
|
+
response = http.request request
|
33
|
+
response.code
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.tweets_request(username, date)
|
37
|
+
path = "/1.1/statuses/user_timeline.json"
|
38
|
+
query = URI.encode_www_form(
|
39
|
+
"screen_name" => username,
|
40
|
+
"count" => 300)
|
41
|
+
address = URI("#{@base_url}#{path}?#{query}")
|
42
|
+
request = Net::HTTP::Get.new address.request_uri
|
43
|
+
http = Net::HTTP.new address.host, address.port
|
44
|
+
http.use_ssl = true
|
45
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
46
|
+
request.oauth! http, @consumer_key, @access_token
|
47
|
+
http.start
|
48
|
+
response = http.request request
|
49
|
+
if response.code != "200"
|
50
|
+
puts "\nYou probably gave an invalid twitter handle"
|
51
|
+
Helper.exit_message
|
52
|
+
exit
|
53
|
+
end
|
54
|
+
tweets_json = File.open("./full_tweets_#{username}.json", "w+")
|
55
|
+
tweets_json << response.body
|
56
|
+
tweets_json.close
|
57
|
+
tweets_hash = JSON.parse(File.read("./full_tweets_#{username}.json"))
|
58
|
+
tweets_only = File.open("./tweets_only_#{username}.json", "w+")
|
59
|
+
tweets_hash.each do |tweets|
|
60
|
+
if Date.parse(tweets["created_at"]) < date
|
61
|
+
break
|
62
|
+
end
|
63
|
+
tweets_only << tweets["text"] + " "
|
64
|
+
end
|
65
|
+
tweets_only.close
|
66
|
+
end
|
67
|
+
end
|
data/lib/helper.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
module Helper
|
2
|
+
# Sort Hashes in descending frequencing
|
3
|
+
|
4
|
+
def self.remove_stop_words(tweets_words)
|
5
|
+
tweets = tweets_words
|
6
|
+
stop_words = []
|
7
|
+
File.open("./stop_words.yml", "r").each do |x|
|
8
|
+
stop_words << x
|
9
|
+
end
|
10
|
+
stop_words = stop_words.join(" ").split(",")
|
11
|
+
stop_words_free = []
|
12
|
+
tweets.each do |word|
|
13
|
+
if stop_words.include?word
|
14
|
+
nil
|
15
|
+
else
|
16
|
+
stop_words_free << word
|
17
|
+
end
|
18
|
+
end
|
19
|
+
stop_words_free.join(" ")
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.sort_hash_descend(value)
|
23
|
+
sorted_hash = Hash.new
|
24
|
+
value.sort_by { |_x, y| -y }.each do |val|
|
25
|
+
sorted_hash[val[0]] = val[1]
|
26
|
+
end
|
27
|
+
sorted_hash
|
28
|
+
end
|
29
|
+
|
30
|
+
# Counts the occurence of words in a string and returns 'word => frequency'
|
31
|
+
def self.words_counter(words)
|
32
|
+
word_list = words.split(" ")
|
33
|
+
word_map = Hash.new
|
34
|
+
word_list.each do |word|
|
35
|
+
word.downcase!
|
36
|
+
next unless word.length > 2
|
37
|
+
if word_map.key?(word)
|
38
|
+
word_map[word] += 1
|
39
|
+
else
|
40
|
+
word_map[word] = 1
|
41
|
+
end
|
42
|
+
end
|
43
|
+
word_map
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.rank_words(okay_words)
|
47
|
+
Helper.sort_hash_descend(Helper.words_counter(okay_words))
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.display_ranking(ranked_words)
|
51
|
+
if ranked_words.length < 1
|
52
|
+
|
53
|
+
exit
|
54
|
+
end
|
55
|
+
longest_key = ranked_words.keys.max_by(&:length)
|
56
|
+
print "\n+#{'-' * longest_key.length}--+#{'-' * 11}+\n"
|
57
|
+
printf "| %-#{longest_key.length}s | %-9s |\n", "Word", "Frequency"
|
58
|
+
print "+#{'-' * longest_key.length}--+#{'-' * 11}+\n"
|
59
|
+
ranked_words.each do |key, value|
|
60
|
+
printf "| %-#{longest_key.length}s | %-6s |\n", key, value
|
61
|
+
end
|
62
|
+
print "+#{'-' * longest_key.length}--+#{'-' * 11}+\n\n"
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.exit_message
|
66
|
+
puts "\nThank you for your time. pls follow @andela and"
|
67
|
+
puts "@mubarakadeimam on Twitter"
|
68
|
+
end
|
69
|
+
end
|
data/stop_words.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
the,a,able,about,across,after,all,almost,also,am,among,an,and,any,are,as,at,be,because,been,but,by,can,cannot,could,dear,did,do,does,either,else,ever,every,for,from,get,got,had,has,have,he,her,hers,him,his,how,however,i,if,in,into,is,it,its,just,least,let,like,likely,may,me,might,most,must,my,neither,no,nor,not,of,off,often,on,only,or,other,our,own,rather,said,say,says,she,should,since,so,some,than,that,the,their,them,then,there,these,they,this,tis,to,too,twas,us,wants,was,we,were,what,when,where,which,while,who,whom,why,will,with,would,yet,you,your,above,afterwards,again,against,alone,along,already,although,always,amongst,amoungst,amount,another,anyhow,anyone,anything,anyway,anywhere,around,back,became,become,becomes,becoming,before,beforehand,behind,being,below,beside,besides,between,beyond,bill,both,bottom,call,cant,co,con,couldnt,cry,de,describe,detail,done,down,due,during,each,eg,eight,eleven,elsewhere,empty,enough,etc,even,everyone,everything,everywhere,except,few,fifteen,fify,fill,find,fire,first,five,former,formerly,forty,found,four,front,full,further,give,go,hasnt,hence,here,hereafter,hereby,herein,hereupon,herself,himself,hundred,ie,inc,indeed,interest,itself,keep,last,latter,latterly,less,ltd,made,many,meanwhile,mill,mine,more,moreover,mostly,move,much,myself,name,namely,never,nevertheless,next,nine,nobody,none,noone,nothing,now,nowhere,once,one,onto,others,otherwise,ours,ourselves,out,over,part,per,perhaps,please,put,re,same,see,seem,seemed,seeming,seems,serious,several,show,side,sincere,six,sixty,somehow,someone,something,sometime,sometimes,somewhere,still,such,system,take,ten,themselves,thence,thereafter,thereby,therefore,therein,thereupon,thickv,thin,third,those,though,three,through,throughout,thru,thus,together,top,toward,towards,twelve,twenty,two,un,under,until,up,upon,very,via,well,whatever,whence,whenever,whereafter,whereas,whereby,wherein,whereupon,wherever,whether,whither,whoever,whole,whose,within,without,yours,yourself,yourselves,computer,thick,http,https,www,
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: andeltsa
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mubarakadeimam
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-26 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.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: oauth
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: colorize
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubygems
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: date
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Carries out Tweets analysis using Alchemy Sentiment Analysis API
|
98
|
+
email: mubarakadeimam@yahoo.com
|
99
|
+
executables:
|
100
|
+
- andeltsa
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- CODE_OF_CONDUCT.md
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- andeltsa.gemspec
|
111
|
+
- api_key.txt
|
112
|
+
- bin/andeltsa
|
113
|
+
- bin/console
|
114
|
+
- bin/setup
|
115
|
+
- lib/.rubocop.yml
|
116
|
+
- lib/alchemy_connect.rb
|
117
|
+
- lib/andeltsa.rb
|
118
|
+
- lib/andeltsa/version.rb
|
119
|
+
- lib/connection.rb
|
120
|
+
- lib/helper.rb
|
121
|
+
- stop_words.yml
|
122
|
+
homepage: https://github.com/mubarakadeimam/TwitterSentimentAnalyzer
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata:
|
126
|
+
allowed_push_host: https://rubygems.org
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 2.4.5.1
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: An Andela Bootcamp Project
|
147
|
+
test_files: []
|