last_tweet 0.5.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2efa81f35b2102928499299a02e9ac1c960e0763480db383a9bc01d4238ece1c
4
+ data.tar.gz: bbd655e08ea44dbeacc4990059c40a35b874471127b57ddb4ab6a0903924d315
5
+ SHA512:
6
+ metadata.gz: e3f4338a67f23d215ed9a5cffba124847fde6a3fd31bc1341b73a715578c69737b47c95b2fd66864f9331768b190d29526f4776ca30e314cc4bb4a798a9305ac
7
+ data.tar.gz: 65194cf4d44b2c86acee250baf4ca6bbd5656ef88a485ab795875be96afd2bd9e925e2f15021f5da6739cf076003d142c2a6fa18e1b0bfbd8a64148941d24c16
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at 'harrishaynes@gmail.com'. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 'Randall Harris Haynes'
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.
@@ -0,0 +1,82 @@
1
+ # last_tweet
2
+
3
+ Ruby gem that displays the most recent tweet from all specified Twitter handles.
4
+
5
+ Before prompting for user input, a list of the five most popular Twitter accounts is provided based on http://friendorfollow.com/twitter/most-followers/.
6
+
7
+ For each Twitter handle specified, the latest tweet is displayed by scraping [https://twitter.com/](https://twitter.com/)handle.
8
+
9
+ ## Usage
10
+
11
+ Run `last_tweet` after installing the gem.
12
+
13
+ ### Example
14
+
15
+ ```diff
16
+ + last_tweet
17
+
18
+ Please specify one or more Twitter handles to see their most recent tweet.
19
+ Sample format 1: @twitter_handle
20
+ Sample format 2: @twitter_handle1, @twitter_handle2, etc.
21
+
22
+ If interested the 5 most popular accounts are listed below.
23
+ - 1: KATY PERRY - @katyperry
24
+ - 2: Justin Bieber - @justinbieber
25
+ - 3: Barack Obama - @BarackObama
26
+ - 4: Rihanna - @rihanna
27
+ - 5: Taylor Swift - @taylorswift13
28
+
29
+ Whose tweet(s) would you like to see? Enter exit when finished.
30
+ + @taylorswift13
31
+ - @taylorswift13 at 2:24 PM - 5 Feb 2018
32
+ - Taylor Swift: The old Taylor can't come to the phone right now.
33
+ - Songs I’m loving right now http://Taylor.lk/SongsTaylorLoves …
34
+
35
+ Whose tweet(s) would you like to see next? Enter exit when finished.
36
+ + @SpaceX, @elonmusk
37
+ - @SpaceX at 7:46 PM - 6 Feb 2018
38
+ - SpaceX: SpaceX designs, manufactures and launches the world’s most advanced rockets and spacecraft.
39
+ - Third burn successful. Exceeded Mars orbit and kept going to the Asteroid Belt.pic.twitter.com/bKhRN73WHF
40
+
41
+ - @elonmusk at 2:01 PM - 7 Feb 2018
42
+ - Elon Musk
43
+ - Last pic of Starman in Roadster on its journey to Mars orbit and then the Asteroid Belt https://www.instagram.com/p/Be6VZEzgAEk/
44
+
45
+ Whose tweet(s) would you like to see next? Enter exit when finished.
46
+ + exit
47
+ - Goodbye!
48
+ ```
49
+
50
+ ## Installation
51
+
52
+ Add this line to your application's Gemfile:
53
+
54
+ ```ruby
55
+ gem 'last_tweet'
56
+ ```
57
+
58
+ And then execute:
59
+
60
+ $ bundle
61
+
62
+ Or install it yourself as:
63
+
64
+ $ gem install last_tweet
65
+
66
+ ## Development
67
+
68
+ 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.
69
+
70
+ 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).
71
+
72
+ ## Contributing
73
+
74
+ Bug reports and pull requests are welcome on GitHub at https://github.com/'rhhaynes'/last_tweet. 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.
75
+
76
+ ## License
77
+
78
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
79
+
80
+ ## Code of Conduct
81
+
82
+ Everyone interacting in the LastTweet project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/'rhhaynes'/last_tweet/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "last_tweet"
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(__FILE__)
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "last_tweet"
5
+
6
+ LastTweet::CLI.new.call
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "last_tweet/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "last_tweet"
8
+ spec.version = LastTweet::VERSION
9
+ spec.authors = ["'Randall Harris Haynes'"]
10
+ spec.email = ["'harrishaynes@gmail.com'"]
11
+
12
+ spec.summary = "Returns the most recent tweet from all specified Twitter handles."
13
+ spec.homepage = "https://github.com/rhhaynes/last-tweet-cli-app"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.executables = ["last_tweet"]
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.16"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_runtime_dependency "colorize"
25
+ spec.add_runtime_dependency "nokogiri"
26
+ end
@@ -0,0 +1,12 @@
1
+ require "colorize"
2
+ require "nokogiri"
3
+ require "open-uri"
4
+
5
+ require_relative "last_tweet/version"
6
+ require_relative "last_tweet/cli"
7
+ require_relative "last_tweet/scraper"
8
+ require_relative "last_tweet/tweet"
9
+ require_relative "last_tweet/twitter_account"
10
+
11
+ module LastTweet
12
+ end
@@ -0,0 +1,61 @@
1
+ class LastTweet::CLI
2
+
3
+ def call
4
+ welcome
5
+ show_popular
6
+ show_menu
7
+ goodbye
8
+ end
9
+
10
+ def welcome
11
+ puts
12
+ puts "Please specify one or more Twitter handles to see their most recent tweet."
13
+ puts "Sample format 1: @twitter_handle"
14
+ puts "Sample format 2: @twitter_handle1, @twitter_handle2, etc."
15
+ puts
16
+ end
17
+
18
+ def show_popular
19
+ puts "If interested the 5 most popular accounts are listed below."
20
+ @twitter_accounts = LastTweet::TwitterAccount.most_popular
21
+ @twitter_accounts.each.with_index(1) do |account,i|
22
+ puts "#{i}: #{account.name} - #{account.handle}".colorize(:blue)
23
+ end
24
+ puts
25
+ end
26
+
27
+ def show_menu
28
+ puts "Whose tweet(s) would you like to see? Enter exit when finished."
29
+ @user_input = 'not_exit'
30
+ until @user_input.downcase == 'exit'
31
+ @user_input = gets.strip
32
+ unless @user_input.downcase == 'exit'
33
+ show_tweets
34
+ puts "Whose tweet(s) would you like to see next? Enter exit when finished."
35
+ end
36
+ end
37
+ end
38
+
39
+ def show_tweets
40
+ twitter_handles = @user_input.gsub(",", " ").split
41
+ twitter_handles.collect do |handle|
42
+ handle = @twitter_accounts[handle.to_i-1].handle if (1..5).include? handle.to_i
43
+ tweet = LastTweet::Tweet.create_from_handle(handle)
44
+ if tweet.message == nil
45
+ puts "Last tweet by #{tweet.account.handle} could not be found. If correct, the account may be private or suspended.".colorize(:red)
46
+ tweet.remove
47
+ else
48
+ puts "#{tweet.account.handle} at #{tweet.timestamp}".colorize(:blue)
49
+ tweet.account.bio.empty? ? puts("#{tweet.account.name}".colorize(:blue)) : puts("#{tweet.account.name}: #{tweet.account.bio}".colorize(:blue))
50
+ puts "#{tweet.message}".colorize(:green)
51
+ end
52
+ puts
53
+ end
54
+ end
55
+
56
+ def goodbye
57
+ puts "Goodbye!".colorize(:blue)
58
+ puts
59
+ end
60
+
61
+ end
@@ -0,0 +1,21 @@
1
+ class LastTweet::Scraper
2
+
3
+ def self.scrape(url, what_to_scrape)
4
+ begin
5
+ page = Nokogiri::HTML(open(url))
6
+ attributes = what_to_scrape.collect do |k,v|
7
+ case v[2]
8
+ when 'hash_key' then [ k, page.css(v[0]).first[ v[1] ] ]
9
+ when 'method' then [ k, page.css(v[0]).first.send(v[1]) ]
10
+ else [ k, page.css(v[0]).first.send(v[1]) ]
11
+ end
12
+ end
13
+
14
+ rescue
15
+ attributes = what_to_scrape.collect{|k,v| [ k, nil ]}
16
+
17
+ end
18
+ attributes.to_h
19
+ end
20
+
21
+ end
@@ -0,0 +1,38 @@
1
+ class LastTweet::Tweet
2
+ attr_accessor :account, :message, :timestamp
3
+ @@all = []
4
+
5
+ def self.all
6
+ @@all
7
+ end
8
+
9
+ def self.create_from_handle(t_handle)
10
+ url = "https://twitter.com/" + t_handle[1..-1]
11
+ message_qry = ["div.tweet div.content div.js-tweet-text-container p.tweet-text", "text", "method"]
12
+ timestamp_qry = ["div.tweet div.content div.stream-item-header small.time a.tweet-timestamp", "title", "hash_key"]
13
+ what_to_scrape = {message: message_qry, timestamp: timestamp_qry}
14
+ twitter_hash = LastTweet::Scraper.scrape(url, what_to_scrape)
15
+
16
+ unless all.any?{|twt| twt.message == twitter_hash[:message] && twt.timestamp == twitter_hash[:timestamp]}
17
+ tweet = new
18
+ tweet.message = twitter_hash[:message]
19
+ tweet.timestamp = twitter_hash[:timestamp]
20
+ tweet.add_account(t_handle)
21
+ @@all << tweet
22
+ end
23
+
24
+ all.detect{|twt| twt.message == twitter_hash[:message] && twt.timestamp == twitter_hash[:timestamp]}
25
+ end
26
+
27
+ def add_account(t_handle)
28
+ t_account = LastTweet::TwitterAccount.all.detect{|acct| acct.handle == t_handle}
29
+ t_account ? self.account = t_account : self.account = LastTweet::TwitterAccount.create_from_handle(t_handle)
30
+ self.account.tweets << self unless self.account.tweets.include? self
31
+ end
32
+
33
+ def remove
34
+ self.account.remove
35
+ @@all.delete(self)
36
+ end
37
+
38
+ end
@@ -0,0 +1,43 @@
1
+ class LastTweet::TwitterAccount
2
+ attr_accessor :handle, :url, :name, :bio, :tweets
3
+ @@all = []
4
+
5
+ def self.all
6
+ @@all
7
+ end
8
+
9
+ def self.create_from_handle(t_handle)
10
+ unless all.any?{|acct| acct.handle == t_handle}
11
+ account = new
12
+ account.handle = t_handle
13
+ account.url = "https://twitter.com/" + t_handle[1..-1]
14
+
15
+ name_qry = ["div.ProfileHeaderCard h1.ProfileHeaderCard-name a.ProfileHeaderCard-nameLink", "text", "method"]
16
+ bio_qry = ["div.ProfileHeaderCard p.ProfileHeaderCard-bio", "text", "method"]
17
+ what_to_scrape = {name: name_qry, bio: bio_qry}
18
+ twitter_hash = LastTweet::Scraper.scrape(account.url, what_to_scrape)
19
+
20
+ account.name = twitter_hash[:name]
21
+ account.bio = twitter_hash[:bio]
22
+ account.tweets = []
23
+
24
+ @@all << account
25
+ end
26
+ all.detect{|acct| acct.handle == t_handle}
27
+ end
28
+
29
+ def self.most_popular(n=5)
30
+ url = "http://friendorfollow.com/twitter/most-followers/"
31
+ n.times.collect do |i|
32
+ handle_qry = ["div\#list-container ul.view-list li.row-#{i+1} div.text-holder a", "text", "method"]
33
+ what_to_scrape = {handle: handle_qry}
34
+ twitter_hash = LastTweet::Scraper.scrape(url, what_to_scrape)
35
+ create_from_handle(twitter_hash[:handle])
36
+ end
37
+ end
38
+
39
+ def remove
40
+ @@all.delete(self)
41
+ end
42
+
43
+ end
@@ -0,0 +1,3 @@
1
+ module LastTweet
2
+ VERSION = "0.5.0"
3
+ end
data/spec.md ADDED
@@ -0,0 +1,10 @@
1
+ # Specifications for the CLI Assessment
2
+
3
+ Specs:
4
+ - [x] Have a CLI for interfacing with the application
5
+ - [x] Pull data from an external source
6
+ - [x] Implement both list and detail views
7
+
8
+ Before prompting for user input, a list of the five most popular Twitter accounts is provided by pulling data from http://friendorfollow.com/twitter/most-followers/.
9
+
10
+ For each specified Twitter handle, the latest tweet is displayed by scraping [https://twitter.com/](https://twitter.com/)handle.
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: last_tweet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - "'Randall Harris Haynes'"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-21 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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: colorize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - "'harrishaynes@gmail.com'"
72
+ executables:
73
+ - last_tweet
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - CODE_OF_CONDUCT.md
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/last_tweet
85
+ - bin/setup
86
+ - last_tweet.gemspec
87
+ - last_tweet_demonstration.mov
88
+ - lib/last_tweet.rb
89
+ - lib/last_tweet/cli.rb
90
+ - lib/last_tweet/scraper.rb
91
+ - lib/last_tweet/tweet.rb
92
+ - lib/last_tweet/twitter_account.rb
93
+ - lib/last_tweet/version.rb
94
+ - spec.md
95
+ homepage: https://github.com/rhhaynes/last-tweet-cli-app
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.7.4
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Returns the most recent tweet from all specified Twitter handles.
119
+ test_files: []