ZMediumToMarkdown 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/ZMediumFetcher +41 -30
  3. data/lib/Helper.rb +2 -1
  4. data/lib/Post.rb +8 -3
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f7805fe04110dc50c764983746065030b4cc87865810de1a50c3b5b89f646d0
4
- data.tar.gz: 5eb355fcd4b28a1d0e704e80b5e3e564e770b681f4cd40302f556e647e3cda95
3
+ metadata.gz: 29245a0299d0f492d7000a27c97f4cfdd305b5bd39b31d1dfbdfd126f938daf1
4
+ data.tar.gz: 7a81eca7da5c8a3d02b80936f2395ff1385ff37ef7092a5f6ae919e9dc817065
5
5
  SHA512:
6
- metadata.gz: ff70606758386f70dc7fdc9ce1a8a45c6e4c6a136f27403794217be4f0acb59b94b00d2caca74f4ba6b464691fa1312ea2e9e94caf20785c5c758ced7de0aa6d
7
- data.tar.gz: d50e747c1acdd6f1f3536711a5c1f15e2fcb729741efe584f8e878fb13e9a461b664e34b0143aef879e1504054ecb108204cb8521a1be200e9cfae52a1a1c8f0
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
- Helper.createDirIfNotExist(postPathPolicy.getAbsolutePath(nil))
240
- index = 0
241
- File.open(absolutePath, "w+") do |file|
242
- # write postInfo into top
243
-
244
- file.puts(Helper.createPostInfo(postInfo))
245
-
246
- paragraphs.each do |paragraph|
247
- markupParser = MarkupParser.new(postHtml, paragraph)
248
- paragraph.text = markupParser.parse()
249
- result = startParser.parse(paragraph)
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
- file.puts(result)
256
-
257
- index += 1
258
- progress.currentPostParagraphIndex = index
259
- progress.message = "Converting Post..."
260
- progress.printLog()
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
- file.puts(Helper.createWatermark(postURL))
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 "https://github.com/ZhgChgLi/ZMediumToMarkdown"
323
- puts "Thanks for using this tool."
324
- puts "If this is helpful, please help to star the repo or recommend it to your friends."
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 = DateTime.strptime(firstPublishedAt.to_s,'%Q')
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ZMediumToMarkdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ZhgChgLi