daily-trending-apps 0.1.7 → 0.1.8

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
  SHA256:
3
- metadata.gz: 2f37b6f4c7eb7b32f7e42ca614fe3e44217c1c0f537b6cd3a219d951fe95c3d2
4
- data.tar.gz: 00b5050ff39947692f921cd5c79f2a862218cb9331836a8f297ac73d86558b90
3
+ metadata.gz: 9d64862a39481fe7803dbc67e92bf17d1430e955308530bc5785c36d42d8b4ef
4
+ data.tar.gz: 179567ec2b353889b6cac6468a7d68b56d718672f18d064977e947c67a1d468f
5
5
  SHA512:
6
- metadata.gz: 9a50592eaa10f7cff2e8dd4013ff2b2caa6389f4096ff45bab70b4469f39bd8cef523caec6fbc943cf306765e13fdfa5377ea7c6824df32e00a237592aa57430
7
- data.tar.gz: 84513f514a08d4a815fe3af575a718ba023fb11d353a8b1a37e4d1863d9490fbe32dc3ef6cb32ecfbf2578589ece2b7c9b7cd20d6a3b0dc9c525cb5322fce26c
6
+ metadata.gz: c076c5c33ebd88ffee0ca7ee20811ddf39c8afa45ee46a0ccdd00bd111aa046e523ff255f2a9f3408be119b26aee586b42f3598ef609c4ae206e9e1d90a1ae31
7
+ data.tar.gz: 2888a2fc353c1d7fef7331bd15069d058854028c259f4a6f787ead460928bed88238e2b54df0de64a499bdeadefcac1f3ee5c076e652d96728106bb68908e67a
@@ -3,22 +3,13 @@ class DailyTrending::App
3
3
  @@all = []
4
4
 
5
5
 
6
-
7
- # Iterates #scrape_play_store method to # Makes the apps and assigns
8
- # the attributes available on Google play store
9
-
6
+ def self.all
7
+ @@all
8
+ end
10
9
 
11
10
 
12
- # def self.make_apps
13
- def self.new_from_index(a)
14
- app = self.new
15
- app.title = a.css('a.title').attribute('title').value
16
- app.dev = a.css('a.subtitle').attribute('title').value
17
- app.dev_url = ("https://play.google.com" + a.css('a.subtitle').attribute('href').value)
18
- app.app_url = ("https://play.google.com" + a.css('a.title').attribute('href').value)
19
- app.rating = a.css('div.tiny-star').attribute('aria-label').value.strip.slice(/\d.\S/)<<"/5 Stars"
20
- app.price = a.at_css('span.display-price').text
21
- app.exist? ? all.freeze : app.save
11
+ def self.find(input)
12
+ @@all[input.to_i-1]
22
13
  end
23
14
 
24
15
 
@@ -31,16 +22,7 @@ class DailyTrending::App
31
22
  @@all << self
32
23
  end
33
24
 
34
- def self.all
35
- @@all
36
- end
37
-
38
-
39
- def make_app(xml_info)
40
- page = xml_info
41
- self.genre = page.css('a.document-subtitle.category').text
42
- self.description = page.css('div.show-more-content.text-body').text
43
- self.con_rating = page.css('span.document-subtitle.content-rating-title').text
44
- self.rate_cnt = page.css('span.rating-count').text
25
+ def open_in_browser
26
+ system("open '#{app_url}'")
45
27
  end
46
28
  end
@@ -3,7 +3,6 @@ class DailyTrending::Cli
3
3
  def call
4
4
  list_apps
5
5
  menu
6
- goodbye
7
6
  end
8
7
 
9
8
  def list_apps
@@ -11,9 +10,8 @@ class DailyTrending::Cli
11
10
  puts ""
12
11
  puts " #{s}"+"New And Updated Apps!"+s
13
12
  puts ""
14
-
15
- @apps = DailyTrending::Scraper.make_apps unless @apps != nil
16
- @apps.each.with_index(1) do |app, i|
13
+ DailyTrending::Scraper.new.scrape_index_page
14
+ DailyTrending::App.all.each.with_index(1) do |app, i|
17
15
  puts <<-DOC
18
16
  #{i}. #{app.title.colorize(:blue)}
19
17
  #{app.rating} Cost: #{app.price}
@@ -21,27 +19,31 @@ class DailyTrending::Cli
21
19
  DOC
22
20
  end
23
21
  puts ""
22
+ puts "Enter the number of the app you'd like more info on, or type exit"
24
23
  end
25
24
 
26
- def menu
27
- input = nil
28
- until input == 'exit'
29
- puts "Enter the number of the app you'd like more info on, or type exit"
30
- input = gets.strip.downcase
31
-
32
- if input.to_i > 0
33
- app_info(@apps[input.to_i-1])
34
- elsif input == 'list'
35
- list_apps
36
- else
37
- puts "#{input} not an option, type list or exit" unless input == 'exit'
38
- end
25
+
26
+ def menu
27
+ input = nil
28
+ until input == 'exit'
29
+ input = gets.strip.downcase
30
+
31
+ if input.to_i > 0 && input.to_i <= DailyTrending::App.all.size
32
+ app_info(DailyTrending::App.find(input))
33
+ elsif input == 'list'
34
+ list_apps
35
+ elsif input == 'exit'
36
+ goodbye
37
+ else
38
+ puts " #{input} not an option, type list or exit" unless input == 'exit'
39
39
  end
40
40
  end
41
+ end
42
+
43
+
41
44
 
42
45
  def app_info(app)
43
- xml_info = DailyTrending::Scraper.scrape_app(app.app_url)
44
- app.make_app(xml_info)
46
+ DailyTrending::Scraper.new.scrape_app(app)
45
47
  puts <<-DOC
46
48
  #{app.title.upcase.colorize(:blue)}
47
49
  Developers: #{app.dev}
@@ -58,23 +60,28 @@ class DailyTrending::Cli
58
60
  More Apps By #{app.dev}: #{app.dev_url.colorize(:red)}
59
61
 
60
62
  DOC
61
- input = nil
63
+ # open_browser(app)
64
+
62
65
  puts " Type 'list' to see apps again or 'exit' to leave"
63
- until input == 'list'|| input == 'exit'
64
- input = gets.strip.downcase
65
- if input == 'list'
66
- list_apps
67
- elsif input == 'exit'
68
- goodbye
69
- exit
70
- else
71
- puts " #{input} not an option, type list or exit" unless input == 'exit'
72
- end
73
- end
66
+ menu
74
67
  end
75
68
 
76
69
 
77
- def goodbye
78
- puts "See you next time!!"
79
- end
70
+ def goodbye
71
+ puts "See you next time!!"
72
+ exit
73
+ end
74
+
75
+
76
+ # def open_browser(app)
77
+ # puts "Would you like to visit this App page?? (y/n)"
78
+ # input = gets.strip.downcase
79
+ #
80
+ # if input == 'y'
81
+ # app.open_in_browser
82
+ # else
83
+ # list_apps
84
+ # end
85
+ # end
86
+
80
87
  end
@@ -1,19 +1,33 @@
1
1
  class DailyTrending::Scraper
2
2
 
3
- def self.scrape_play_store
4
- doc = Nokogiri::HTML(open("https://play.google.com/store/apps/collection/promotion_3000792_new_releases_apps?clp=SpEBCikKI3Byb21vdGlvbl8zMDAwNzkyX25ld19yZWxlYXNlc19hcHBzEAcYAxpkCl5uZXdfaG9tZV9kZXZpY2VfZmVhdHVyZWRfcmVjczJfdG9waWNfdjFfbGF1bmNoX2FwcHNfVVNfXzE1MTQ0NDgwMDAwMDBfNl9wcm9tb18xNTE0NDkxNzcwMTgwMDAwEAwYAw%3D%3D%3AS%3AANO1ljLrBj0&hl=en"))
5
- doc.css('div.card-content.id-track-click.id-track-impression')
3
+
4
+ def initialize
5
+ @base_link = "https://play.google.com"
6
6
  end
7
+ # Why was instance variable @base_link not available in #scrape_app before I made #initialize??
8
+ # Didn't work in #scrape_app when I assigned it in #scrape_index_page
7
9
 
8
- def self.make_apps
9
- scrape_play_store.each do |a|
10
- DailyTrending::App.new_from_index(a)
10
+ def scrape_index_page
11
+ index_page = Nokogiri::HTML(open("#{@base_link}/store/apps/collection/promotion_3000792_new_releases_apps?clp=SpEBCikKI3Byb21vdGlvbl8zMDAwNzkyX25ld19yZWxlYXNlc19hcHBzEAcYAxpkCl5uZXdfaG9tZV9kZXZpY2VfZmVhdHVyZWRfcmVjczJfdG9waWNfdjFfbGF1bmNoX2FwcHNfVVNfXzE1MTQ0NDgwMDAwMDBfNl9wcm9tb18xNTE0NDkxNzcwMTgwMDAwEAwYAw%3D%3D%3AS%3AANO1ljLrBj0&hl=en"))
12
+ index_page.css('div.card-content.id-track-click.id-track-impression').each do |a|
13
+ app = DailyTrending::App.new
14
+ app.title = a.css('a.title').attribute('title').value
15
+ app.app_url = (@base_link + a.css('a.title').attribute('href').value)
16
+ app.rating = a.css('div.tiny-star').attribute('aria-label').value.strip.slice(/\d.\S/)<<"/5 Stars"
17
+ app.price = a.at_css('span.display-price').text
18
+ app.exist? ? DailyTrending::App.all.freeze : app.save
11
19
  end
12
- DailyTrending::App.all
13
20
  end
14
21
 
15
- def self.scrape_app(app_url)
16
- Nokogiri::HTML(open(app_url))
17
- end
18
22
 
23
+ def scrape_app(app)
24
+ page = Nokogiri::HTML(open(app.app_url))
25
+ app.dev = page.css('a.document-subtitle.primary').text.strip
26
+ app.dev_url = (@base_link + page.css('a.document-subtitle.primary').attribute('href').value)
27
+ app.genre = page.css('a.document-subtitle.category').text.strip
28
+ app.description = page.css('div.show-more-content.text-body').text
29
+ app.con_rating = page.css('span.document-subtitle.content-rating-title').text
30
+ app.rate_cnt = page.css('span.rating-count').text
31
+ app
32
+ end
19
33
  end
@@ -1,3 +1,3 @@
1
1
  module DailyTrending
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daily-trending-apps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - "'Chad Montoya'"
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-06 00:00:00.000000000 Z
11
+ date: 2018-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler