tumblr_draftking 0.8.5 → 0.9.0

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
  SHA1:
3
- metadata.gz: d6b5f77dda0c0d3fc5e5bf4c4aeaff660dd6f94e
4
- data.tar.gz: 4b59cd291c87baaaaef3e9d26f1a15a8015b0a71
3
+ metadata.gz: 049132366daff875b43a74dfdbd429cf778baeb7
4
+ data.tar.gz: e40794d1bdcb8d41a22627d75d682d370337ebcc
5
5
  SHA512:
6
- metadata.gz: 5179163cc06b43b23434a6d823931d3015e2d05a54228a52f7e93865347942b711c2e20bc53b96000ef54dc7c5711b3bd19ca4b07ea75970010726e94c8c7e54
7
- data.tar.gz: 192a53ce61efd8e3180198530fc1cc8f1dc14869869677b255f13736a86ec82614c4d4eaf6d49cc90a5353a4588148bb7c41c6cb1da5ca058caf487c9124cd96
6
+ metadata.gz: a47bbd200d6283ffad17da8322a05f514d7814bd17d1d3891459f1121859919e29d338dc6ffb150f352b5e04675bdb0a9f1485207087c22d6ea3af199c7c939c
7
+ data.tar.gz: 876764909b4983d5078ad0a620cf1698bf1ead4df28068148a36ab193c9ff2abb926a870de2d63bdf23199a01adab315db2648547c8bf930f70be86650d7652f
data/CHANGELOG.md CHANGED
@@ -1,4 +1,7 @@
1
1
  # Changelog :: tumblr_draftking
2
+ ## Version 0.9.0
3
+ + New! Batch upload and comment photos from a file.
4
+
2
5
  ## Version 0.8.5
3
6
  + Stability improvement for post retrieval routine
4
7
 
data/README.md CHANGED
@@ -6,7 +6,8 @@ DraftKing is not associated with Tumblr
6
6
  [![Test Coverage](https://codeclimate.com/github/meissadia/tumblr_draftking/badges/coverage.svg)](https://codeclimate.com/github/meissadia/tumblr_draftking/coverage)
7
7
 
8
8
  DraftKing for Tumblr takes the hassle out of managing your draft queue!
9
- + **(New!) [Auto-Poster](#auto-poster): Publish up to 200 posts a day!**
9
+ + **(New!) [Batch Uploader](#batch-uploader): Upload a list of URLs/files**
10
+ + **[Auto-Poster](#auto-poster): Publish up to 200 posts a day!**
10
11
  + **Save and name your own [DK commands](#custom-commands)!**
11
12
  + **Automate the addition of comments and tags.**
12
13
  + **Strip away old comments.**
@@ -14,8 +15,8 @@ DraftKing for Tumblr takes the hassle out of managing your draft queue!
14
15
  + **Randomize post order to add variety.**
15
16
  + **Manage multiple accounts.**
16
17
 
17
- Version 0.8.5
18
- + Stability improvement for post retrieval routine
18
+ Version 0.9.0
19
+ + New! Batch upload and comment photos from a file.
19
20
 
20
21
  + Please report any [issues] you encounter!
21
22
  + [Change Log](./CHANGELOG.md)
@@ -38,6 +39,7 @@ Version 0.8.5
38
39
  + [Stripping Comments](#stripping-comments)
39
40
  + [Comment & Move](#comment-&-move)
40
41
  + [Auto-Poster](#auto-poster)
42
+ + [Batch Uploader](#batch-uploader)
41
43
  + [Testing Console](#testing-console)
42
44
  + [API](#api)
43
45
  + [Built With](#built-with)
@@ -232,6 +234,16 @@ $ dk md -c "draftking for tumblr" -k -t new,tags,to,add -m
232
234
 
233
235
  ```ruby
234
236
  $ dk ap -b 'test-blog' -c 'draftking auto poster' -k -t 'new,tags,to,add' -s :drafts
237
+ ```
238
+
239
+ ##### Batch Uploader
240
+ - Provide input file (-f FILE_PATH)
241
+ - Upload to secondary blog (-b BLOG_NAME)
242
+ - Provide a url to visit when photo is clicked (-l LINK_URL)
243
+ - Add tags #blog2, #my upload (-t)
244
+
245
+ ```ruby
246
+ $ dk ups -f /Users/meis/Desktop/new_stuff.txt -b blog2 -l blog2.tumblr.com -t 'blog2, my upload,'
235
247
  ```
236
248
 
237
249
  #### Testing Console
@@ -59,5 +59,9 @@ module DK
59
59
  end
60
60
  end
61
61
  end
62
+
63
+ def current_date_string
64
+ Time.now.strftime('%b %d, %H:%M:%S')
65
+ end
62
66
  end
63
67
  end
@@ -6,7 +6,7 @@ module DK
6
6
  d = {}
7
7
  d[:add_tags] = 'Comma separated string of tags to add.'
8
8
  d[:blog] = 'Name of blog to use. Excluding this will default to main blog.'
9
- d[:comment] = 'Comment to add to any posts which do not already contain it.'
9
+ d[:comment] = 'A caption that gets added to your posts.'
10
10
  d[:config] = 'Name or # of Config to use (`dk accounts` for list)'
11
11
  d[:credit] = 'Give draftking credit with a tag'
12
12
  d[:keep_comments] = 'Keep the previous comments on a post.'
@@ -20,6 +20,8 @@ module DK
20
20
  d[:state] = 'Set post state: d-draft, q-queued'
21
21
  d[:tags] = 'Auto-Generate tags based on user comment.'
22
22
  d[:greedy] = 'Select entire queue before processing the action.'
23
+ d[:file] = 'File path.'
24
+ d[:link] = 'URL to visit when photo is clicked.'
23
25
  d
24
26
  end
25
27
 
@@ -0,0 +1,135 @@
1
+ module DK
2
+ class CLI < Thor
3
+ desc 'uploads, ups', 'Batch upload photos from url list.'
4
+ long_desc <<-LONGDESC
5
+ `uploads` will create Drafts from a list of photo urls.
6
+
7
+ *** Input File Format ***
8
+
9
+ Line type indicators:
10
+ - (Start of a new caption group)
11
+ # (Ignore this line during processing)
12
+
13
+ Example File:
14
+
15
+ -
16
+ Group 1 post caption
17
+ http://example.com/picture1.jpg
18
+ http://example.com/picture2.jpg
19
+ #this line is commented out
20
+ #http://example.com/bad_url.png
21
+ /path/to/file/group1/group1_pic.png
22
+ -
23
+ # this group has no caption
24
+ http://example.com/picture3.jpg
25
+ http://example.com/picture4.jpg
26
+ /path/to/file/picture5.png
27
+
28
+
29
+ LONGDESC
30
+ option :file, type: :string, aliases: :f, desc: Options.op_strings[:file], required: true
31
+ option :link, type: :string, aliases: :l, desc: Options.op_strings[:link]
32
+ option :blog, type: :string, aliases: :b, desc: Options.op_strings[:blog]
33
+ option :simulate, type: :boolean, aliases: :s, desc: Options.op_strings[:simulate]
34
+ option :mute, type: :boolean, aliases: :m, desc: Options.op_strings[:mute]
35
+ option :add_tags, type: :string, aliases: :t, desc: Options.op_strings[:add_tags]
36
+ option :config, type: :string, desc: Options.op_strings[:config]
37
+ def uploads
38
+ configured?
39
+ opts = process_options(options)
40
+ dk = get_dk_instance(opts)
41
+ dfile = opts[:file].chomp.strip
42
+
43
+ File.open(dfile, 'r') do |data_file|
44
+ mod = 0
45
+ rows = []
46
+ caption = ''
47
+ row = Struct.new(:count, :line, :file, :caption, :status)
48
+ title = ups_title(dfile, dk)
49
+ data_file.each_line.with_index do |line, idx|
50
+ line = line.chomp.strip
51
+ next if line.empty? || is_commented?(line)
52
+ (caption = nil) || next if is_url_group?(line)
53
+ (caption = line) && next if is_caption?(line, caption)
54
+ ups_progress(mod, caption) unless dk.mute
55
+ post_opts = ups_opts(line, caption, dk, opts)
56
+ status = ups_photo_draft(dk, post_opts)
57
+ rows << row.new(mod += 1, idx + 1, File.basename(line), caption, status)
58
+ end # each_line
59
+ ups_report(title, dk, rows)
60
+ end # of data_file
61
+ end # of uploads
62
+
63
+ map 'ups' => :uploads # command alias
64
+
65
+ private
66
+
67
+ def is_url_group?(line)
68
+ line.start_with?('-')
69
+ end
70
+
71
+ def is_caption?(line, caption)
72
+ caption.nil? && (!is_file?(line) || !is_url?(line))
73
+ end
74
+
75
+ def is_commented?(line)
76
+ line.start_with? '#'
77
+ end
78
+
79
+ def is_file?(line)
80
+ line.start_with?('/')
81
+ end
82
+
83
+ def is_url?(line)
84
+ line.start_with?('http')
85
+ end
86
+
87
+ def ups_photo_draft(dk, post_opts)
88
+ result = { 'id' => 'success' }
89
+ result = dk.client.photo(dk.blog_name, post_opts) unless dk.simulate
90
+ result['id'] ? '√' : result['errors'].first
91
+ end
92
+
93
+ def ups_opts(line, caption, dk, opts)
94
+ post_opts = {
95
+ caption: caption,
96
+ state: dk.state,
97
+ tags: comment_to_tags(caption)
98
+ }
99
+ is_url?(line) ? (post_opts[:source] = line) : (post_opts[:data] = [line])
100
+ post_opts[:tags] += ",#{dk.tags}" unless dk.tags.nil?
101
+ post_opts[:link] = opts[:link] unless opts[:link].nil?
102
+ post_opts
103
+ end
104
+
105
+ def ups_report(title, dk, rows)
106
+ r = DK::Reporter.new(
107
+ title: title,
108
+ fields: DK::UPLOAD_FIELDS,
109
+ simulate: dk.simulate,
110
+ objects: rows
111
+ )
112
+ print ' ' * 80 + "\r\n" # erase_line
113
+ puts "\n#{r}\n" unless dk.mute
114
+ end
115
+
116
+ def ups_title(file, dk)
117
+ "DK Batch Uploader\n" \
118
+ "Input: #{file}\n" \
119
+ "Target: #{dk.blog_name} [ #{dk.state.capitalize} ]\n" \
120
+ "#{current_date_string}"
121
+ end
122
+
123
+ def ups_progress(mod, caption)
124
+ msg = "Current group: #{caption} • "
125
+ show_progress(current: mod, total: mod, message: msg)
126
+ end
127
+
128
+ def comment_to_tags(comment)
129
+ comment += " | #{DK::CREDIT_TAG}"
130
+ comment.slice!('bc / ') # Remove prefix
131
+ comment.gsub(%r{[\/\\|]}, ',') # Convert Separators
132
+ .gsub(' , ', ',') # Clean up tags
133
+ end
134
+ end # of CLI
135
+ end # of DK
data/lib/draftking/cli.rb CHANGED
@@ -12,6 +12,7 @@ require_relative 'cli/commands/movedrafts'
12
12
  require_relative 'cli/commands/strip'
13
13
  require_relative 'cli/commands/status'
14
14
  require_relative 'cli/commands/tag'
15
+ require_relative 'cli/commands/uploads'
15
16
 
16
17
  # Stored User Commands
17
18
  require_relative 'cli/commands/user_command'
@@ -14,7 +14,7 @@ module DK
14
14
  attr_accessor :shuffle, :keep_tree, :test_data, :mute
15
15
  attr_accessor :simulate, :keep_tags, :before_id, :credit
16
16
  attr_accessor :message, :source, :auto_tag, :state
17
- attr_accessor :type
17
+ attr_accessor :type, :tags
18
18
 
19
19
  # Initialize instance of DraftKing for the specified blog
20
20
  # @param options[:blog_name] [String] Target blog name
@@ -22,5 +22,8 @@ module DK
22
22
  # PostReporter
23
23
  REPORT_TITLE = 'Post Report'.freeze
24
24
  REPORT_FIELDS = %w(id state comment tags).freeze
25
- REPORT_SIM = ' (SIMULATION)'.freeze
25
+ REPORT_SIM = '(SIMULATION)'.freeze
26
+
27
+ # Uploads
28
+ UPLOAD_FIELDS = %w(count line file caption status).freeze
26
29
  end
@@ -34,7 +34,7 @@ module DK
34
34
  options[:message] = 'Moving Drafts -> Queue: '
35
35
  options[:shuffle] = true
36
36
  options[:state] = DK::QUEUE
37
- options[:limit] ||= options[:greedy] ? nil : @q_space
37
+ options[:limit] = options[:greedy] ? (nil || options[:limit]) : @q_space
38
38
  post_operation(options) do |post, index|
39
39
  next false unless index_within_limit?(index, @q_space)
40
40
  next false unless post.has_key_text?(@key_text)
@@ -8,6 +8,7 @@ module DK
8
8
  options[:message] = 'Moving Queue ~> Drafts: '
9
9
  options[:shuffle] = false
10
10
  options[:state] = DK::DRAFT
11
+ options[:source] ||= DK::QUEUE
11
12
  post_operation(options) do |post, _|
12
13
  post.changed = !post.has_key_text?(@key_text)
13
14
  post.change_state(@state) if post.changed
@@ -16,7 +16,7 @@ module DK
16
16
  # @param opts[:simulate] [Boolean] Show simulation indicator
17
17
  # @param opts[:title] [String] Report Title
18
18
  def build_title(opts)
19
- "#{opts[:title]}#{REPORT_SIM if opts[:simulate]}"
19
+ "#{opts[:title]}#{"\n" + REPORT_SIM if opts[:simulate]}"
20
20
  end
21
21
 
22
22
  # Determine Field List
@@ -1,3 +1,3 @@
1
1
  module DK
2
- VERSION = '0.8.5'.freeze
2
+ VERSION = '0.9.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tumblr_draftking
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.5
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Meissa Dia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-29 00:00:00.000000000 Z
11
+ date: 2018-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tumblr_client
@@ -124,6 +124,7 @@ files:
124
124
  - lib/draftking/cli/commands/status.rb
125
125
  - lib/draftking/cli/commands/strip.rb
126
126
  - lib/draftking/cli/commands/tag.rb
127
+ - lib/draftking/cli/commands/uploads.rb
127
128
  - lib/draftking/cli/commands/user_command.rb
128
129
  - lib/draftking/client.rb
129
130
  - lib/draftking/config.rb