ZMediumToMarkdown 1.2.0 → 1.3.0

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: 837c899a0d017fa83febc0f96e84a89527a517754cbee44f6e91320c7b2cd292
4
- data.tar.gz: cb5c49e7a67f99ab888cb0797edaf4c0ce237da3e8c41bfda963395bd606b1cd
3
+ metadata.gz: 478b02a8d17067e64ef3c402640961cc75c91a560b0370e598be80ee17b27296
4
+ data.tar.gz: 2b01dcc7f9950271bcb0f4e59f10c2c6a1015cd1d013df796e62a4b2138ba69e
5
5
  SHA512:
6
- metadata.gz: f9339415de8183d6c255bf28db437c61e8913c242e5ed3270d070285b1282717187511a974fdc6c0ef391c37a6308bcf3d7f866dd0fa508a7e00fc004d05ca87
7
- data.tar.gz: 832198d0d8cf5851aedfa7f69a9193cad42f71f21f06fb29a832957140fdfd6d8e3099429b8085824eae2f19d0d05c6c2615f73d012fa16679fcf49945918862
6
+ metadata.gz: 3dbf24729dae8e94881fa876ef9cb2119ee1370b45160c3aa6974ee84cb6522ae85ff5380c600db2420df32ec5ec50ac00350f7e56cf41177cc56ed186845ac1
7
+ data.tar.gz: c62b15539cd70a2d6523f3d89ded3a88ac5220ca72896d7a163d557cc2d1ccbcfec94b548ed78920b74fbe05ef52d18c0b8f4fe57cf832a7f17e2d7f72dd2224
@@ -12,34 +12,40 @@ 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
39
47
 
40
48
  end.parse!
41
-
42
- Helper.logLatestRunVersion()
43
49
  end
44
50
  end
45
51
 
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.0
4
+ version: 1.3.0
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