ZMediumToMarkdown 1.1.0 → 1.2.2

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: 29245a0299d0f492d7000a27c97f4cfdd305b5bd39b31d1dfbdfd126f938daf1
4
- data.tar.gz: 7a81eca7da5c8a3d02b80936f2395ff1385ff37ef7092a5f6ae919e9dc817065
3
+ metadata.gz: f4927555e3c7d6f021e1c989a83e03a095f613d28fc482d3f08599d16229dbc0
4
+ data.tar.gz: 77753af16833d4927574a3a170b3d046f35688c1a7146b85a857ca6fcad35851
5
5
  SHA512:
6
- metadata.gz: 592b4a98e54ea032aee4560c23a827637fcfe38bc56b66af7cb1b5799e3a1b8b641f20de03566e96f04b9b8a75ddf97b97e339503f5b49c55afa599a8cdbf31b
7
- data.tar.gz: e2003629feee6fe3230d4c72059a860e9be0458e28a5fee7640a13c4aa1ef5ec2047d27a21fa8a7a719d19bb601efa245dcec24461738bf0cdc113e6ed1e694c
6
+ metadata.gz: 55d662074d29bae6267a7982f3f03c61264b6a5628f2ca15aa9b06a70d3d8d329505f5c833700b8580743719885afe99fb090e3d50ea7a720c5848d56a557e6f
7
+ data.tar.gz: 5a3ac99f7b8ea47bc24f8f2f48b8f5147fa86d2f8bba920be4592be08ae6f2b7434a545ec353fc879f65ca4ac34dc5285273c17f97f58a66d345072db678863b
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ $lib = File.expand_path('../lib', File.dirname(__FILE__))
5
+ $LOAD_PATH.unshift($lib)
6
+
7
+ require "ZMediumFetcher"
8
+ require "Helper"
9
+ require "optparse"
10
+
11
+ class Main
12
+ def initialize
13
+ fetcher = ZMediumFetcher.new
14
+ ARGV << '-h' if ARGV.empty?
15
+ OptionParser.new do |opts|
16
+ opts.banner = "Usage: ZMediumFetcher [options]"
17
+
18
+ opts.on('-uUSERNAME', '--username=USERNAME', 'Downloading all posts from user') do |username|
19
+ pathPolicy = PathPolicy.new("#{File.expand_path('../', File.dirname(__FILE__))}", "Output")
20
+ fetcher.downloadPostsByUsername(username, pathPolicy)
21
+
22
+ Helper.printNewVersionMessageIfExists()
23
+ end
24
+
25
+ opts.on('-pPOST_URL', '--postURL=POST_URL', 'Downloading single post') do |postURL|
26
+ pathPolicy = PathPolicy.new("#{File.expand_path('../', File.dirname(__FILE__))}", "Output")
27
+ fetcher.downloadPost(postURL, pathPolicy)
28
+
29
+ Helper.printNewVersionMessageIfExists()
30
+ end
31
+
32
+ opts.on('-n', '--new', 'Update to latest version') do |postURL|
33
+ if Helper.compareVersion(Helper.getRemoteVersionFromGithub(), Helper.getLocalVersionFromGemspec())
34
+ Helper.downloadLatestVersion()
35
+ else
36
+ puts "You're using the latest version :)"
37
+ end
38
+ end
39
+
40
+ end.parse!
41
+
42
+ Helper.logLatestRunVersion()
43
+ end
44
+ end
45
+
46
+ begin
47
+ puts "#https://github.com/ZhgChgLi/ZMediumToMarkdown"
48
+ puts "You have read and agree with the Disclaimer."
49
+ Main.new()
50
+ puts "Execute Successfully!!!"
51
+ puts "#https://github.com/ZhgChgLi/ZMediumToMarkdown"
52
+ puts "#Thanks for using this tool."
53
+ puts "#If this is helpful, please help to star the repo or recommend it to your friends."
54
+ rescue => e
55
+ puts "#Error: #{e.class} #{e.message}\n"
56
+ puts e.backtrace
57
+ puts "#Please feel free to open an Issue or submit a fix/contribution via Pull Request on:\n"
58
+ puts "#https://github.com/ZhgChgLi/ZMediumToMarkdown\n"
59
+ end
data/lib/Helper.rb CHANGED
@@ -1,9 +1,30 @@
1
1
  $lib = File.expand_path('../lib', File.dirname(__FILE__))
2
2
 
3
+ require 'fileutils'
3
4
  require 'date'
5
+ require 'PathPolicy'
4
6
  require 'Post'
7
+ require "Request"
8
+ require 'json'
9
+ require 'open-uri'
10
+ require 'zip'
5
11
 
6
12
  class Helper
13
+
14
+ class Version
15
+ attr_accessor :major, :minor, :patch
16
+
17
+ def initialize(major, minor, patch)
18
+ @major = major.to_i
19
+ @minor = minor.to_i
20
+ @patch = patch.to_i
21
+ end
22
+
23
+ def to_string()
24
+ "#{major.to_s}.#{minor.to_s}.#{patch.to_s}"
25
+ end
26
+ end
27
+
7
28
  def self.createDirIfNotExist(dirPath)
8
29
  dirs = dirPath.split("/")
9
30
  currentDir = ""
@@ -24,6 +45,45 @@ class Helper
24
45
  puts "####################################################\n"
25
46
  end
26
47
 
48
+ def self.downloadLatestVersion()
49
+ apiPath = 'https://api.github.com/repos/ZhgChgLi/ZMediumToMarkdown/releases'
50
+ versions = JSON.parse(Request.URL(apiPath).body).sort { |a,b| b["id"] <=> a["id"] }
51
+
52
+ version = nil
53
+ index = 0
54
+ while version == nil do
55
+ thisVersion = versions[index]
56
+ if thisVersion["prerelease"] == false
57
+ version = thisVersion
58
+ next
59
+ end
60
+ index += 1
61
+ end
62
+
63
+ zipFilePath = version["zipball_url"]
64
+ puts "Downloading latest version from github..."
65
+ open('latest.zip', 'wb') do |fo|
66
+ fo.print open(zipFilePath).read
67
+ end
68
+
69
+ puts "Unzip..."
70
+ Zip::File.open("latest.zip") do |zipfile|
71
+ zipfile.each do |file|
72
+ fileNames = file.name.split("/")
73
+ fileNames.shift
74
+ filePath = fileNames.join("/")
75
+ if filePath != ''
76
+ puts "Unzinp...#{filePath}"
77
+ zipfile.extract(file, filePath) { true }
78
+ end
79
+ end
80
+ end
81
+ File.delete("latest.zip")
82
+
83
+ tagName = version["tag_name"]
84
+ puts "Update to version #{tagName} successfully!"
85
+ end
86
+
27
87
  def self.createPostInfo(postInfo)
28
88
  result = "---\n"
29
89
  result += "title: #{postInfo.title}\n"
@@ -36,6 +96,68 @@ class Helper
36
96
  result
37
97
  end
38
98
 
99
+ def self.printNewVersionMessageIfExists()
100
+ if Helper.compareVersion(Helper.getRemoteVersionFromGithub(), Helper.getLocalVersionFromGemspec())
101
+ puts "##########################################################"
102
+ puts "##### New Version Available!!! #####"
103
+ puts "##### Please type `bin/ZMediumToMarkdown -n` to update!!##"
104
+ puts "##########################################################"
105
+ end
106
+ end
107
+
108
+ def self.getLocalVersionFromGemspec()
109
+ rootPath = File.expand_path('../', File.dirname(__FILE__))
110
+ gemspecContent = File.read("#{rootPath}/ZMediumToMarkdown.gemspec")
111
+ result = gemspecContent[/(gem\.version){1}\s+(\=)\s+(\'){1}(\d+(\.){1}\d+(\.){1}\d+){1}(\'){1}/, 4]
112
+
113
+ if !result.nil?
114
+ versions = result.split(".")
115
+ Version.new(versions[0],versions[1],versions[2])
116
+ else
117
+ nil
118
+ end
119
+ end
120
+
121
+ def self.getRemoteVersionFromGithub()
122
+ apiPath = 'https://api.github.com/repos/ZhgChgLi/ZMediumToMarkdown/releases'
123
+ versions = JSON.parse(Request.URL(apiPath).body).sort { |a,b| b["id"] <=> a["id"] }
124
+
125
+ tagName = nil
126
+ index = 0
127
+ while tagName == nil do
128
+ thisVersion = versions[index]
129
+ if thisVersion["prerelease"] == false
130
+ tagName = thisVersion["tag_name"]
131
+ next
132
+ end
133
+ index += 1
134
+ end
135
+
136
+ if !tagName.nil?
137
+ versions = (tagName.downcase.gsub! 'v','') .split(".")
138
+ Version.new(versions[0],versions[1],versions[2])
139
+ else
140
+ nil
141
+ end
142
+ end
143
+
144
+ def self.compareVersion(version1, version2)
145
+ if version1.major > version2.major
146
+ true
147
+ else
148
+ if version1.minor > version2.minor
149
+ true
150
+ else
151
+ if version1.patch > version2.patch
152
+ true
153
+ else
154
+ false
155
+ end
156
+ end
157
+ end
158
+ end
159
+
160
+
39
161
  def self.createWatermark(postURL)
40
162
  text = "\r\n\r\n\r\n"
41
163
  text += "+-----------------------------------------------------------------------------------+"
@@ -1,13 +1,8 @@
1
- #!/usr/bin/env ruby
2
- # -*- coding: utf-8 -*-
1
+
3
2
 
4
3
  $lib = File.expand_path('../lib', File.dirname(__FILE__))
5
- $LOAD_PATH.unshift($lib)
6
4
 
7
- require "open-uri"
8
- require 'json'
9
- require 'optparse'
10
- require 'fileutils'
5
+ require "fileutils"
11
6
 
12
7
  require "Parsers/H1Parser"
13
8
  require "Parsers/H2Parser"
@@ -32,26 +27,6 @@ require "Request"
32
27
  require "Post"
33
28
  require "User"
34
29
 
35
- class Main
36
- def initialize
37
- fetcher = ZMediumFetcher.new
38
- ARGV << '-h' if ARGV.empty?
39
- OptionParser.new do |opts|
40
- opts.banner = "Usage: ZMediumFetcher [options]"
41
-
42
- opts.on('-uUSERNAME', '--username=USERNAME', 'test') do |username|
43
- pathPolicy = PathPolicy.new("#{File.expand_path('../', File.dirname(__FILE__))}", "Output")
44
- fetcher.downloadPostsByUsername(username, pathPolicy)
45
- end
46
-
47
- opts.on('-pPOST_URL', '--postURL=POST_URL', 'test') do |postURL|
48
- pathPolicy = PathPolicy.new("#{File.expand_path('../', File.dirname(__FILE__))}", "Output")
49
- fetcher.downloadPost(postURL, pathPolicy)
50
- end
51
- end.parse!
52
- end
53
- end
54
-
55
30
  class ZMediumFetcher
56
31
 
57
32
  attr_accessor :progress, :linkParser
@@ -323,19 +298,4 @@ class ZMediumFetcher
323
298
  progress.message = "All posts has been downloaded!, Total posts: #{postURLS.length}"
324
299
  progress.printLog()
325
300
  end
326
- end
327
-
328
- begin
329
- puts "#https://github.com/ZhgChgLi/ZMediumToMarkdown"
330
- puts "You have read and agree with the Disclaimer."
331
- Main.new()
332
- puts "Execute Successfully!!!"
333
- puts "#https://github.com/ZhgChgLi/ZMediumToMarkdown"
334
- puts "#Thanks for using this tool."
335
- puts "#If this is helpful, please help to star the repo or recommend it to your friends."
336
- rescue => e
337
- puts "#Error: #{e.class} #{e.message}\n"
338
- puts e.backtrace
339
- puts "#Please feel free to open an Issue or submit a fix/contribution via Pull Request on:\n"
340
- puts "#https://github.com/ZhgChgLi/ZMediumToMarkdown\n"
341
301
  end
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.1.0
4
+ version: 1.2.2
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-29 00:00:00.000000000 Z
11
+ date: 2022-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -56,11 +56,11 @@ description: ZMediumToMarkdown lets you download Medium post and convert it to m
56
56
  format easily.
57
57
  email:
58
58
  executables:
59
- - ZMediumFetcher
59
+ - ZMediumToMarkdown
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
- - bin/ZMediumFetcher
63
+ - bin/ZMediumToMarkdown
64
64
  - lib/ErrorHandle.rb
65
65
  - lib/Helper.rb
66
66
  - lib/ImageDownloader.rb
@@ -87,6 +87,7 @@ files:
87
87
  - lib/Post.rb
88
88
  - lib/Request.rb
89
89
  - lib/User.rb
90
+ - lib/ZMediumFetcher.rb
90
91
  homepage: https://github.com/ZhgChgLi/ZMediumToMarkdown
91
92
  licenses:
92
93
  - MIT