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.
- checksums.yaml +4 -4
- data/bin/reddit_junkie +15 -31
- data/lib/reddit_junkie.rb +71 -24
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7247ea36a4057843ec6d72abc643a91d58a44bfd8ead7aa5e31503fdec47d567
|
4
|
+
data.tar.gz: a699a5b3d3dc8b2a5f839967e3bf1cf10b5390cc65e6dfb7a49b074234187f78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35eb9bf50881c274230872fae552e30c0dd38e34106cc556545468799fc956f05ae1cfac49392a60beb8b0ab30141316b6bdf7bd8feb1e31f2167308b446c819
|
7
|
+
data.tar.gz: 15a3cfb0381e4f240437c265976a360f979eab4fcfa7bd77643279dfb775a3cfcdcb8e224358022f9308425db7c5db1287a93c848810d6396cec3d765a90986d
|
data/bin/reddit_junkie
CHANGED
@@ -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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
35
|
-
|
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
|
+
|
data/lib/reddit_junkie.rb
CHANGED
@@ -40,8 +40,8 @@ class RedditImage
|
|
40
40
|
|
41
41
|
def update_data
|
42
42
|
@after_pointer = @after_pointer_temporary
|
43
|
-
|
44
|
-
|
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::
|
66
|
-
|
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
|
-
|
69
|
-
|
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
|
-
|
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
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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.
|
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-
|
11
|
+
date: 2020-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|