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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d175f065345508536bf819ab29db376b591c978d3b32872496f5d8a80d2fb518
4
- data.tar.gz: eeb5c3c303a1daef3e05bce586240d0195f3d32999208b784530a175fe58b89e
3
+ metadata.gz: 462eddc4d4cd64f3eaaf52f1ccb23d84859def2d998ce633a2cd0c5e142e3323
4
+ data.tar.gz: a022fa3ac8d178691bf90bec98cd6a4071b4d58eb6b0ca083171f700c2d8a97e
5
5
  SHA512:
6
- metadata.gz: 6b12ca00410c8946e1736fac5c328b892d5b4d8b08d5074101bb16ac869ad5ef92d7884201a19a0fcadf2e11a9450b407f0573382e81cfa875090768a27822ed
7
- data.tar.gz: 396a75a07a19283d6ce215b32da304ad4f90c72131c87903b8edf04e53ac1e3cf902e61877469367dce4b749fe979c292101cfe12b167290446d3da94826a28e
6
+ metadata.gz: 1599289267a982ab1178993a52bbcf32baa36e442a5697557af0504d4fd5c09ff76c6b0e645f5cf9339850f4c4eb1a999df0f2606e9e36fe772385c2ca92e284
7
+ data.tar.gz: 99f58102d82cb920ebd1d8d2f5b751182037dbaa41362ee321b1759581f37f9fc22c9b35a24b0c05da1b73bcdb5ec4e50d93c347f436cef724d56f607ceb658b
@@ -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', 'test') do |username|
19
- Helper.checkNewVersion()
22
+ opts.on('-uUSERNAME', '--username=USERNAME', 'Downloading all posts from user') do |username|
23
+ fetcher.downloadPostsByUsername(username, outputFilePath)
20
24
 
21
- pathPolicy = PathPolicy.new("#{File.expand_path('../', File.dirname(__FILE__))}", "Output")
22
- fetcher.downloadPostsByUsername(username, pathPolicy)
25
+ Helper.printNewVersionMessageIfExists()
23
26
  end
24
27
 
25
- opts.on('-pPOST_URL', '--postURL=POST_URL', 'test') do |postURL|
26
- Helper.checkNewVersion()
28
+ opts.on('-pPOST_URL', '--postURL=POST_URL', 'Downloading single post') do |postURL|
29
+ fetcher.downloadPost(postURL, outputFilePath)
27
30
 
28
- pathPolicy = PathPolicy.new("#{File.expand_path('../', File.dirname(__FILE__))}", "Output")
29
- fetcher.downloadPost(postURL, pathPolicy)
31
+ Helper.printNewVersionMessageIfExists()
30
32
  end
31
33
 
32
- opts.on('-n', '--new', 'Update to latest version') do |postURL|
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.checkNewVersion()
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
- response = self.URL(response['location'], method, data)
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
@@ -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 forceDownload == false && File.file?(absolutePath) && File.mtime(absolutePath) >= postInfo.latestPublishedAt
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.2.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-05-30 00:00:00.000000000 Z
11
+ date: 2022-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri