brutalismbot 1.0.0 → 1.1.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: bf7eecddaa253c115bad51e282827083c828b4060833ddbeba331312afa25c1b
4
- data.tar.gz: 0ed7cef7623794bbe0353a08e61c2f3e6fac10194573f0b13ea28c671bda82dd
3
+ metadata.gz: d4320503af32170415ba481d307ecf9c2b20b9de51b5ca7458e89da22a87bfbc
4
+ data.tar.gz: 0d1e83cc91bbe9b601eeabb8ceac2d373cfd218b46c181814e71bb7cc43b422c
5
5
  SHA512:
6
- metadata.gz: 3fe8b7d235d61027da57d0e2b8cc22390913b8da198045aff70a1ab6d7571893bd3985f93074d2d2965f9eb289dee9780a2bd65e10d519a3558010de94fc64c8
7
- data.tar.gz: 655f2fe2db79f125e47ded1c59fe729d47f676cbf2d9db1ba63d8835f7ce1d9292ddb4d17a7cb53ae7a3b9a7ada4afb2dc8e5418fabc5aec02425fd493de0450
6
+ metadata.gz: 57c0307cdbc4b362e89bca101f73d3dc95ff83b3b73c71ab797fe982f0084598c1e4797334d1fba0f83e9084a58b8c0325d310848c4cf813caeeefbf6bc7ffe8
7
+ data.tar.gz: 5989867f8a3e555178393490928e3e3b655f7fc9005e1d75016f6de5218ce53688effc51791d2fe6823e637208b3526c70aa1c87083ae3820f74b0599bb2b3b1
@@ -19,18 +19,21 @@ module Brutalismbot
19
19
  lag.empty? ? 9000 : lag.to_i
20
20
  end
21
21
 
22
- def pull(min_time:nil, max_time:nil, dryrun:nil)
22
+ def pull(limit:nil, min_time:nil, max_time:nil, dryrun:nil)
23
23
  # Get time window for new posts
24
24
  min_time ||= @posts.max_time
25
25
  max_time ||= Time.now.utc.to_i - lag_time
26
26
 
27
27
  # Get posts
28
28
  posts = @reddit.list(:new)
29
+
30
+ # Filter, sort, and limit
29
31
  posts = posts.select{|post| post.created_between?(min_time, max_time) }
30
32
  posts = posts.sort{|a,b| a.created_utc <=> b.created_utc }
33
+ posts = posts.slice(0, limit) unless limit.nil?
31
34
 
32
35
  # Persist posts
33
- posts.each{|post| @posts.push(post, dryrun: dryrun) }
36
+ posts.map{|post| @posts.push(post, dryrun: dryrun) }
34
37
  end
35
38
 
36
39
  def push(post, dryrun:nil)
@@ -53,6 +53,7 @@ module Brutalismbot
53
53
  key = key_for(post)
54
54
  Brutalismbot.logger.info("PUT #{"DRYRUN " if dryrun}s3://#{@bucket.name}/#{key}")
55
55
  @bucket.put_object(key: key, body: post.to_json) unless dryrun
56
+ {bucket: @bucket.name, key: key}
56
57
  end
57
58
  end
58
59
  end
@@ -22,18 +22,22 @@ module Brutalismbot
22
22
  Time.at(data["created_utc"].to_i).utc
23
23
  end
24
24
 
25
- def fullname
26
- "#{kind}_#{id}"
27
- end
28
-
29
25
  def data
30
26
  @item.fetch("data", {})
31
27
  end
32
28
 
29
+ def fullname
30
+ "#{kind}_#{id}"
31
+ end
32
+
33
33
  def id
34
34
  data["id"]
35
35
  end
36
36
 
37
+ def inspect
38
+ "#<#{self.class} #{data["permalink"]}>"
39
+ end
40
+
37
41
  def kind
38
42
  @item["kind"]
39
43
  end
@@ -50,16 +54,6 @@ module Brutalismbot
50
54
  CGI.unescapeHTML(data["title"])
51
55
  end
52
56
 
53
- def url
54
- images = data.dig("preview", "images") || {}
55
- source = images.map{|x| x["source"] }.compact.max do |a,b|
56
- a.slice("width", "height").values <=> b.slice("width", "height").values
57
- end
58
- CGI.unescapeHTML(source.dig("url"))
59
- rescue NoMethodError
60
- data["media_metadata"]&.values&.first&.dig("s", "u")
61
- end
62
-
63
57
  def to_slack
64
58
  url.nil? ? to_slack_text : to_slack_image
65
59
  end
@@ -112,6 +106,16 @@ module Brutalismbot
112
106
  def to_twitter
113
107
  [title, permalink].join("\n")
114
108
  end
109
+
110
+ def url
111
+ images = data.dig("preview", "images") || {}
112
+ source = images.map{|x| x["source"] }.compact.max do |a,b|
113
+ a.slice("width", "height").values <=> b.slice("width", "height").values
114
+ end
115
+ CGI.unescapeHTML(source.dig("url"))
116
+ rescue NoMethodError
117
+ data["media_metadata"]&.values&.first&.dig("s", "u")
118
+ end
115
119
  end
116
120
  end
117
121
  end
@@ -1,3 +1,3 @@
1
1
  module Brutalismbot
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brutalismbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Mancevice
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-02 00:00:00.000000000 Z
11
+ date: 2020-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: twitter