ZMediumToMarkdown 1.2.1 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/ZMediumToMarkdown +21 -11
- data/lib/Helper.rb +1 -22
- data/lib/Request.rb +6 -1
- data/lib/ZMediumFetcher.rb +1 -4
- 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: 462eddc4d4cd64f3eaaf52f1ccb23d84859def2d998ce633a2cd0c5e142e3323
|
4
|
+
data.tar.gz: a022fa3ac8d178691bf90bec98cd6a4071b4d58eb6b0ca083171f700c2d8a97e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1599289267a982ab1178993a52bbcf32baa36e442a5697557af0504d4fd5c09ff76c6b0e645f5cf9339850f4c4eb1a999df0f2606e9e36fe772385c2ca92e284
|
7
|
+
data.tar.gz: 99f58102d82cb920ebd1d8d2f5b751182037dbaa41362ee321b1759581f37f9fc22c9b35a24b0c05da1b73bcdb5ec4e50d93c347f436cef724d56f607ceb658b
|
data/bin/ZMediumToMarkdown
CHANGED
@@ -12,34 +12,44 @@ class Main
|
|
12
12
|
def initialize
|
13
13
|
fetcher = ZMediumFetcher.new
|
14
14
|
ARGV << '-h' if ARGV.empty?
|
15
|
+
|
16
|
+
filePath = File.expand_path File.dirname(__FILE__)
|
17
|
+
outputFilePath = PathPolicy.new(filePath, "Output")
|
18
|
+
|
15
19
|
OptionParser.new do |opts|
|
16
20
|
opts.banner = "Usage: ZMediumFetcher [options]"
|
17
21
|
|
18
|
-
opts.on('-uUSERNAME', '--username=USERNAME', '
|
19
|
-
|
22
|
+
opts.on('-uUSERNAME', '--username=USERNAME', 'Downloading all posts from user') do |username|
|
23
|
+
fetcher.downloadPostsByUsername(username, outputFilePath)
|
20
24
|
|
21
|
-
|
22
|
-
fetcher.downloadPostsByUsername(username, pathPolicy)
|
25
|
+
Helper.printNewVersionMessageIfExists()
|
23
26
|
end
|
24
27
|
|
25
|
-
opts.on('-pPOST_URL', '--postURL=POST_URL', '
|
26
|
-
|
28
|
+
opts.on('-pPOST_URL', '--postURL=POST_URL', 'Downloading single post') do |postURL|
|
29
|
+
fetcher.downloadPost(postURL, outputFilePath)
|
27
30
|
|
28
|
-
|
29
|
-
fetcher.downloadPost(postURL, pathPolicy)
|
31
|
+
Helper.printNewVersionMessageIfExists()
|
30
32
|
end
|
31
33
|
|
32
|
-
opts.on('-n', '--new', 'Update to latest version') do
|
34
|
+
opts.on('-n', '--new', 'Update to latest version') do
|
33
35
|
if Helper.compareVersion(Helper.getRemoteVersionFromGithub(), Helper.getLocalVersionFromGemspec())
|
34
36
|
Helper.downloadLatestVersion()
|
35
37
|
else
|
36
38
|
puts "You're using the latest version :)"
|
37
39
|
end
|
38
40
|
end
|
41
|
+
|
42
|
+
opts.on('-c', '--clean', 'Remove all downloaded posts data') do
|
43
|
+
FileUtils.rm_rf(Dir[outputFilePath.getAbsolutePath(nil)])
|
44
|
+
|
45
|
+
Helper.printNewVersionMessageIfExists()
|
46
|
+
end
|
47
|
+
|
48
|
+
opts.on('-v', '--version', 'Print current ZMediumToMarkdown Version') do
|
49
|
+
puts "Version:#{Helper.getLocalVersionFromGemspec().to_string}"
|
50
|
+
end
|
39
51
|
|
40
52
|
end.parse!
|
41
|
-
|
42
|
-
Helper.logLatestRunVersion()
|
43
53
|
end
|
44
54
|
end
|
45
55
|
|
data/lib/Helper.rb
CHANGED
@@ -96,7 +96,7 @@ class Helper
|
|
96
96
|
result
|
97
97
|
end
|
98
98
|
|
99
|
-
def self.
|
99
|
+
def self.printNewVersionMessageIfExists()
|
100
100
|
if Helper.compareVersion(Helper.getRemoteVersionFromGithub(), Helper.getLocalVersionFromGemspec())
|
101
101
|
puts "##########################################################"
|
102
102
|
puts "##### New Version Available!!! #####"
|
@@ -118,27 +118,6 @@ class Helper
|
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
|
-
def self.logLatestRunVersion()
|
122
|
-
version = Helper.getLocalVersionFromGemspec()
|
123
|
-
rootPath = File.expand_path('../', File.dirname(__FILE__))
|
124
|
-
|
125
|
-
File.open("#{rootPath}/.latestRunVersion" , 'w+') do |file|
|
126
|
-
file.puts(version.to_string())
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
def self.getLocalVersionFromFile()
|
131
|
-
rootPath = File.expand_path('../', File.dirname(__FILE__))
|
132
|
-
result = File.read("#{rootPath}/.latestRunVersion")
|
133
|
-
|
134
|
-
if !result.nil?
|
135
|
-
versions = result.split(".")
|
136
|
-
Version.new(versions[0],versions[1],versions[2])
|
137
|
-
else
|
138
|
-
nil
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
121
|
def self.getRemoteVersionFromGithub()
|
143
122
|
apiPath = 'https://api.github.com/repos/ZhgChgLi/ZMediumToMarkdown/releases'
|
144
123
|
versions = JSON.parse(Request.URL(apiPath).body).sort { |a,b| b["id"] <=> a["id"] }
|
data/lib/Request.rb
CHANGED
@@ -23,12 +23,17 @@ class Request
|
|
23
23
|
end
|
24
24
|
|
25
25
|
response = https.request(request)
|
26
|
+
|
26
27
|
# 3XX Redirect
|
27
28
|
if response.code.to_i >= 300 && response.code.to_i <= 399 && !response['location'].nil? && response['location'] != ''
|
28
29
|
if retryCount >= 10
|
29
30
|
raise "Error: Retry limit reached. path: #{url}"
|
30
31
|
else
|
31
|
-
|
32
|
+
location = response['location']
|
33
|
+
if !location.match? /^(http)/
|
34
|
+
location = "#{uri.scheme}://#{uri.host}#{location}"
|
35
|
+
end
|
36
|
+
response = self.URL(location, method, data)
|
32
37
|
end
|
33
38
|
end
|
34
39
|
response
|
data/lib/ZMediumFetcher.rb
CHANGED
@@ -212,12 +212,9 @@ class ZMediumFetcher
|
|
212
212
|
progress.printLog()
|
213
213
|
|
214
214
|
absolutePath = postPathPolicy.getAbsolutePath("#{postPath}.md")
|
215
|
-
|
216
|
-
# if user latest use's version is < latest local version than force download (don't skip, make sure bug fixed can be influenced)
|
217
|
-
forceDownload = Helper.compareVersion(Helper.getLocalVersionFromGemspec(), Helper.getLocalVersionFromFile())
|
218
215
|
|
219
216
|
# if markdown file is exists and last modification time is >= latestPublishedAt(last update post time on medium)
|
220
|
-
if
|
217
|
+
if File.file?(absolutePath) && File.mtime(absolutePath) >= postInfo.latestPublishedAt
|
221
218
|
# Already downloaded and nothing has changed!, Skip!
|
222
219
|
progress.currentPostParagraphIndex = paragraphs.length
|
223
220
|
progress.message = "Skip, Post already downloaded and nothing has changed!"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ZMediumToMarkdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ZhgChgLi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|