ZMediumToMarkdown 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/ZMediumFetcher +41 -30
- data/lib/Helper.rb +2 -1
- data/lib/Post.rb +8 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29245a0299d0f492d7000a27c97f4cfdd305b5bd39b31d1dfbdfd126f938daf1
|
4
|
+
data.tar.gz: 7a81eca7da5c8a3d02b80936f2395ff1385ff37ef7092a5f6ae919e9dc817065
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 592b4a98e54ea032aee4560c23a827637fcfe38bc56b66af7cb1b5799e3a1b8b641f20de03566e96f04b9b8a75ddf97b97e339503f5b49c55afa599a8cdbf31b
|
7
|
+
data.tar.gz: e2003629feee6fe3230d4c72059a860e9be0458e28a5fee7640a13c4aa1ef5ec2047d27a21fa8a7a719d19bb601efa245dcec24461738bf0cdc113e6ed1e694c
|
data/bin/ZMediumFetcher
CHANGED
@@ -7,6 +7,7 @@ $LOAD_PATH.unshift($lib)
|
|
7
7
|
require "open-uri"
|
8
8
|
require 'json'
|
9
9
|
require 'optparse'
|
10
|
+
require 'fileutils'
|
10
11
|
|
11
12
|
require "Parsers/H1Parser"
|
12
13
|
require "Parsers/H2Parser"
|
@@ -236,36 +237,45 @@ class ZMediumFetcher
|
|
236
237
|
progress.printLog()
|
237
238
|
|
238
239
|
absolutePath = postPathPolicy.getAbsolutePath("#{postPath}.md")
|
239
|
-
|
240
|
-
|
241
|
-
File.
|
242
|
-
#
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
if !linkParser.nil?
|
252
|
-
result = linkParser.parse(result, paragraph.markupLinks)
|
253
|
-
end
|
240
|
+
|
241
|
+
# if markdown file is exists and last modification time is >= latestPublishedAt(last update post time on medium)
|
242
|
+
if File.file?(absolutePath) && File.mtime(absolutePath) >= postInfo.latestPublishedAt
|
243
|
+
# Already downloaded and nothing has changed!, Skip!
|
244
|
+
progress.currentPostParagraphIndex = paragraphs.length
|
245
|
+
progress.message = "Skip, Post already downloaded and nothing has changed!"
|
246
|
+
progress.printLog()
|
247
|
+
else
|
248
|
+
Helper.createDirIfNotExist(postPathPolicy.getAbsolutePath(nil))
|
249
|
+
File.open(absolutePath, "w+") do |file|
|
250
|
+
# write postInfo into top
|
251
|
+
file.puts(Helper.createPostInfo(postInfo))
|
254
252
|
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
253
|
+
index = 0
|
254
|
+
paragraphs.each do |paragraph|
|
255
|
+
markupParser = MarkupParser.new(postHtml, paragraph)
|
256
|
+
paragraph.text = markupParser.parse()
|
257
|
+
result = startParser.parse(paragraph)
|
258
|
+
|
259
|
+
if !linkParser.nil?
|
260
|
+
result = linkParser.parse(result, paragraph.markupLinks)
|
261
|
+
end
|
262
|
+
|
263
|
+
file.puts(result)
|
264
|
+
|
265
|
+
index += 1
|
266
|
+
progress.currentPostParagraphIndex = index
|
267
|
+
progress.message = "Converting Post..."
|
268
|
+
progress.printLog()
|
269
|
+
end
|
270
|
+
|
271
|
+
file.puts(Helper.createWatermark(postURL))
|
261
272
|
end
|
273
|
+
FileUtils.touch absolutePath, :mtime => postInfo.latestPublishedAt
|
262
274
|
|
263
|
-
|
275
|
+
progress.message = "Post Successfully Downloaded!"
|
276
|
+
progress.printLog()
|
264
277
|
end
|
265
|
-
|
266
|
-
progress.message = "Post Successfully Downloaded!"
|
267
|
-
progress.printLog()
|
268
|
-
|
278
|
+
|
269
279
|
progress.postPath = nil
|
270
280
|
end
|
271
281
|
|
@@ -316,12 +326,13 @@ class ZMediumFetcher
|
|
316
326
|
end
|
317
327
|
|
318
328
|
begin
|
319
|
-
puts "https://github.com/ZhgChgLi/ZMediumToMarkdown"
|
329
|
+
puts "#https://github.com/ZhgChgLi/ZMediumToMarkdown"
|
320
330
|
puts "You have read and agree with the Disclaimer."
|
321
331
|
Main.new()
|
322
|
-
puts "
|
323
|
-
puts "
|
324
|
-
puts "
|
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."
|
325
336
|
rescue => e
|
326
337
|
puts "#Error: #{e.class} #{e.message}\n"
|
327
338
|
puts e.backtrace
|
data/lib/Helper.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
$lib = File.expand_path('../lib', File.dirname(__FILE__))
|
2
2
|
|
3
|
+
require 'date'
|
3
4
|
require 'Post'
|
4
5
|
|
5
6
|
class Helper
|
@@ -27,7 +28,7 @@ class Helper
|
|
27
28
|
result = "---\n"
|
28
29
|
result += "title: #{postInfo.title}\n"
|
29
30
|
result += "author: #{postInfo.creator}\n"
|
30
|
-
result += "date: #{postInfo.firstPublishedAt}\n"
|
31
|
+
result += "date: #{postInfo.firstPublishedAt.strftime('%Y-%m-%dT%H:%M:%S.%LZ')}\n"
|
31
32
|
result += "tags: [#{postInfo.tags.join(",")}]\n"
|
32
33
|
result += "---\n"
|
33
34
|
result += "\r\n"
|
data/lib/Post.rb
CHANGED
@@ -9,7 +9,7 @@ require 'date'
|
|
9
9
|
class Post
|
10
10
|
|
11
11
|
class PostInfo
|
12
|
-
attr_accessor :title, :tags, :creator, :firstPublishedAt
|
12
|
+
attr_accessor :title, :tags, :creator, :firstPublishedAt, :latestPublishedAt
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.getPostIDFromPostURLString(postURLString)
|
@@ -59,9 +59,14 @@ class Post
|
|
59
59
|
|
60
60
|
firstPublishedAt = content&.dig("Post:#{postID}", "firstPublishedAt")
|
61
61
|
if !firstPublishedAt.nil?
|
62
|
-
postInfo.firstPublishedAt =
|
62
|
+
postInfo.firstPublishedAt = Time.at(0, firstPublishedAt, :millisecond)
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
|
+
latestPublishedAt = content&.dig("Post:#{postID}", "latestPublishedAt")
|
66
|
+
if !latestPublishedAt.nil?
|
67
|
+
postInfo.latestPublishedAt = Time.at(0, latestPublishedAt, :millisecond)
|
68
|
+
end
|
69
|
+
|
65
70
|
postInfo
|
66
71
|
end
|
67
72
|
end
|