reddit_junkie 0.0.5 → 0.0.6

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/reddit_junkie +15 -31
  3. data/lib/reddit_junkie.rb +71 -24
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71920776834b7262d6b3b0cf592182003a567d15f83559999f8f99c24801dcbb
4
- data.tar.gz: 831af04ddea38a9b74785f9bc6fe0f4453a60456346cd1cf6ffa863d69630a46
3
+ metadata.gz: 7247ea36a4057843ec6d72abc643a91d58a44bfd8ead7aa5e31503fdec47d567
4
+ data.tar.gz: a699a5b3d3dc8b2a5f839967e3bf1cf10b5390cc65e6dfb7a49b074234187f78
5
5
  SHA512:
6
- metadata.gz: a3310ef9a57516b653040fc0716badb935556a4a96135dbd0981a47acacc6efcf2ba6c1f452dce8b1ec09837dab5c50804b1581a4e2da3f7ff2df2062b50fd58
7
- data.tar.gz: 4502f95c1b14e75c6c20f0440cd6dbd05a7bd99fe3f66dada47f8b031e21183b520852441d195fd7904a879c5da3ee9fdc6999a23d61bc51ad6b33014756aae9
6
+ metadata.gz: 35eb9bf50881c274230872fae552e30c0dd38e34106cc556545468799fc956f05ae1cfac49392a60beb8b0ab30141316b6bdf7bd8feb1e31f2167308b446c819
7
+ data.tar.gz: 15a3cfb0381e4f240437c265976a360f979eab4fcfa7bd77643279dfb775a3cfcdcb8e224358022f9308425db7c5db1287a93c848810d6396cec3d765a90986d
@@ -12,41 +12,25 @@ OptionParser.new do |option|
12
12
  option.on("--endpoint ENDPOINT")
13
13
  end.parse!(into: options)
14
14
 
15
- if options[:subreddit] && options[:count] && options[:directory]
15
+ if options[:subreddit] && options[:count] && options[:directory] && options[:endpoint]
16
16
  count = options[:count].to_i
17
- if count%100 == 0
18
- count_max = count / 100
19
- count_min = 0
20
- r = RedditImage.new(options[:subreddit], options[:count].to_i, options[:directory])
21
- while count_min < count_max do
22
- puts "Iteration No. #{count_min + 1}"
23
- r.download_images
24
- r.get_info
25
- r.update_data
26
- count_min += 1
27
- end
28
- else
29
- r = RedditImage.new(options[:subreddit], options[:count].to_i, options[:directory])
30
- r.download_images
31
- end
17
+ r = RedditImage.new(options[:subreddit], count, options[:directory], options[:endpoint])
18
+ r.download_images
19
+ elsif options[:subreddit] && options[:count] && options[:directory]
20
+ count = options[:count].to_i
21
+ r = RedditImage.new(options[:subreddit], count, options[:directory])
22
+ r.download_images
23
+ elsif options[:subreddit] && options[:directory]
24
+ count = 25
25
+ r = RedditImage.new(options[:subreddit], count, options[:directory])
26
+ r.download_images
32
27
  elsif options[:subreddit] && options[:count]
33
28
  count = options[:count].to_i
34
- if count%100 == 0
35
- count_max = count / 100
36
- count_min = 0
37
- r = RedditImage.new(options[:subreddit], options[:count].to_i)
38
- while count_min < count_max do
39
- puts "Iteration No. #{count_min + 1}"
40
- r.download_images
41
- r.get_info
42
- r.update_data
43
- count_min += 1
44
- end
45
- else
46
- r = RedditImage.new(options[:subreddit], options[:count].to_i)
47
- r.download_images
48
- end
29
+ r = RedditImage.new(options[:subreddit], count)
30
+ r.download_images
49
31
  elsif options[:subreddit]
50
32
  r = RedditImage.new(options[:subreddit])
51
33
  r.download_images
52
34
  end
35
+
36
+
@@ -40,8 +40,8 @@ class RedditImage
40
40
 
41
41
  def update_data
42
42
  @after_pointer = @after_pointer_temporary
43
- @index = @index + 1
44
- @directory = @directory + @index.to_s
43
+ #@index = @index + 1
44
+ #@directory = @directory + @index.to_s
45
45
  end
46
46
 
47
47
  def download_images
@@ -61,34 +61,81 @@ class RedditImage
61
61
 
62
62
  json_response = JSON.parse(response.body)
63
63
  data = json_response['data']['children']
64
-
65
- Dir::mkdir("#{@directory}")
66
- Dir::chdir("#{@directory}")
64
+
65
+ if Dir::exists?"#{@directory}"
66
+ puts "The directory \"#{@directory}\" exists!"
67
+ Dir::chdir("#{@directory}")
68
+ else
69
+ Dir::mkdir("#{@directory}")
70
+ Dir::chdir("#{@directory}")
71
+ end
67
72
 
68
- links = []
69
- data.each do |datum|
70
- datum = datum['data']
71
- if datum['post_hint'] == "image"
72
- links << datum['url_overridden_by_dest']
73
- end
74
- end
73
+ count_min = 0
74
+ #count_max = @qty % 100 ? @qty / 100 : "Sorry!"
75
75
 
76
- file_name_base = 1
76
+ if @qty % 100 == 0
77
+ count_max = @qty / 100
78
+ elsif @qty < 100
79
+ count_max = 1
80
+ else
81
+ puts "Sorry, not supported in this version"
82
+ end
83
+
84
+ while count_min < count_max
85
+ if @qty <= 100
86
+ links = []
87
+ data.each do |datum|
88
+ datum = datum['data']
89
+ if datum['post_hint'] == "image"
90
+ links << datum['url_overridden_by_dest']
91
+ end
92
+ end
77
93
 
78
- links.each do |link|
79
- if link != nil
80
- file_name = "#{file_name_base}.jpg"
81
- final_image = File.open(file_name, "wb")
82
- final_image.write(HTTParty.get(link))
83
- puts "Wrote on #{file_name}"
84
- file_name_base += 1
85
- sleep 0.5
86
- final_image.close
94
+ file_name_base = 1
95
+
96
+ links.each do |link|
97
+ if link != nil
98
+ file_name = "#{@sub}-#{file_name_base}.jpg"
99
+ final_image = File.open(file_name, "wb")
100
+ final_image.write(HTTParty.get(link))
101
+ puts "Wrote on #{file_name}"
102
+ file_name_base += 1
103
+ sleep 0.5
104
+ final_image.close
105
+ end
106
+ end
107
+ else
108
+ if count_min > 0
109
+ self.get_info
110
+ self.update_data
111
+ end
112
+ links = []
113
+ data.each do |datum|
114
+ datum = datum['data']
115
+ if datum['post_hint'] == "image"
116
+ links << datum['url_overridden_by_dest']
117
+ end
118
+ end
119
+
120
+ file_name_base = count_min > 0 ? count_min * 100 : 1
121
+
122
+ links.each do |link|
123
+ if link != nil
124
+ file_name = "#{@sub}-#{file_name_base}.jpg"
125
+ final_image = File.open(file_name, "wb")
126
+ final_image.write(HTTParty.get(link))
127
+ puts "Wrote on #{file_name}"
128
+ file_name_base += 1
129
+ sleep 0.5
130
+ final_image.close
131
+ end
132
+ end
87
133
  end
134
+ count_min += 1
88
135
  end
89
-
136
+
90
137
  Dir::chdir("..")
91
138
 
92
139
  return links
93
- end
140
+ end
94
141
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reddit_junkie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Muhammadreza Haghiri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-29 00:00:00.000000000 Z
11
+ date: 2020-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty