feed2gram 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +4 -2
- data/example/Gemfile.lock +1 -1
- data/lib/feed2gram/publishes_posts.rb +26 -9
- data/lib/feed2gram/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24a46cff098342888e3997e1dadfc34a6e0526f979ea59b7b2e0687ecc1051e7
|
4
|
+
data.tar.gz: 63f1559288645c2bb02ddfbe45aa6edd55e5f76437f582f8aec9a12a2c1630fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5eb07918977ad2d034609efbc2372ce3af65f9d75ef6d3766a3eb5db938b955fa3ebe5828091ffc56d0179a138fd433b06d314b3f58e537c71edb5e25ce6ba1
|
7
|
+
data.tar.gz: ad34cbae69b4148ecd5acb953018ef8bbd6c75e61e2fca50514f47a5ac31d061e167ed801e8182d5a735da93a91181b0a8f35175710203d7fa2e0f3a321f09ee
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -101,8 +101,10 @@ Usage: feed2gram [options]
|
|
101
101
|
These environment variables can be set to augment the gem's behavior:
|
102
102
|
|
103
103
|
* `SECONDS_PER_UPLOAD_CHECK` - when uploading video, feed2gram must wait until
|
104
|
-
the [status code](https://tiagogrosso.github.io/instagram-graph-api-lib/enums/CONTAINER_STATUS_CODE.html) on the media indicates it is published. This variable determines how many seconds to wait between each check (defaults to 30 seconds). Shortening this value can lead to hitting one's hourly rate limit
|
105
|
-
* `MAX_UPLOAD_STATUS_CHECKS` - how many status checks to perform before giving up on a piece of media and calling the post failed. Unfortunately, Facebook's servers can take anywhere from 15 seconds to 15 hours to download and process even trivially small videos, so GLHF
|
104
|
+
the [status code](https://tiagogrosso.github.io/instagram-graph-api-lib/enums/CONTAINER_STATUS_CODE.html) on the media indicates it is published. This variable determines how many seconds to wait between each check (defaults to `30` seconds). Shortening this value can lead to hitting one's hourly rate limit
|
105
|
+
* `MAX_UPLOAD_STATUS_CHECKS` - how many status checks to perform before giving up on a piece of media and calling the post failed. Unfortunately, Facebook's servers can take anywhere from 15 seconds to 15 hours to download and process even trivially small videos, so GLHF (defaults to `100` attempts)
|
106
|
+
* `RETRIES_AFTER_UPLOAD_TIMEOUT` - because Facebook's servers will so often hang and fail to download videos (even when you
|
107
|
+
set the timeout to absurd lengths like 20 hours, it'll still report `IN_PROGRESS`), it may be necessary to retry after timeout. (defaults to `5` retries)
|
106
108
|
|
107
109
|
## Formatting your Atom feed's HTML
|
108
110
|
|
data/example/Gemfile.lock
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
module Feed2Gram
|
2
2
|
Result = Struct.new(:post, :status, keyword_init: true)
|
3
|
+
class FacebookSucksAtDownloadingFilesError < StandardError; end
|
3
4
|
|
4
5
|
class PublishesPosts
|
6
|
+
SECONDS_PER_UPLOAD_CHECK = ENV.fetch("SECONDS_PER_UPLOAD_CHECK") { 30 }.to_i
|
7
|
+
MAX_UPLOAD_STATUS_CHECKS = ENV.fetch("MAX_UPLOAD_STATUS_CHECKS") { 100 }.to_i
|
8
|
+
RETRIES_AFTER_UPLOAD_TIMEOUT = ENV.fetch("RETRIES_AFTER_UPLOAD_TIMEOUT") { 5 }.to_i
|
9
|
+
|
5
10
|
def publish(posts, config, options)
|
6
11
|
post_limit = options.limit || posts.size
|
7
12
|
puts "Publishing #{post_limit} posts to Instagram" if options.verbose
|
@@ -9,12 +14,14 @@ module Feed2Gram
|
|
9
14
|
# reverse to post oldest first (most Atom feeds are reverse-chronological)
|
10
15
|
posts.reverse.take(post_limit).map { |post|
|
11
16
|
begin
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
17
|
+
retry_if_upload_times_out(RETRIES_AFTER_UPLOAD_TIMEOUT, post, options) do
|
18
|
+
if post.medias.size == 1
|
19
|
+
puts "Publishing #{post.media_type.downcase} for: #{post.url}" if options.verbose
|
20
|
+
publish_single_media(post, config, options)
|
21
|
+
else
|
22
|
+
puts "Publishing carousel for: #{post.url}" if options.verbose
|
23
|
+
publish_carousel(post, config, options)
|
24
|
+
end
|
18
25
|
end
|
19
26
|
rescue => e
|
20
27
|
warn "Failed to post #{post.url}: #{e.message}"
|
@@ -26,6 +33,18 @@ module Feed2Gram
|
|
26
33
|
|
27
34
|
private
|
28
35
|
|
36
|
+
def retry_if_upload_times_out(times_remaining, post, options, &blk)
|
37
|
+
blk.call
|
38
|
+
rescue FacebookSucksAtDownloadingFilesError
|
39
|
+
if times_remaining > 0
|
40
|
+
puts "Will retry with attempt ##{RETRIES_AFTER_UPLOAD_TIMEOUT - times_remaining + 2} after Facebook failed to download a video without timing out for: #{post.url}" if options.verbose
|
41
|
+
retry_if_upload_times_out(times_remaining - 1, post, options, &blk)
|
42
|
+
else
|
43
|
+
warn "Failed to post #{post.url} after #{RETRIES_AFTER_UPLOAD_TIMEOUT} retries due to Facebook timing out on video downloads"
|
44
|
+
Result.new(post: post, status: :failed)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
29
48
|
def publish_single_media(post, config, options)
|
30
49
|
media = post.medias.first
|
31
50
|
|
@@ -82,15 +101,13 @@ module Feed2Gram
|
|
82
101
|
Result.new(post: post, status: :posted)
|
83
102
|
end
|
84
103
|
|
85
|
-
SECONDS_PER_UPLOAD_CHECK = ENV.fetch("SECONDS_PER_UPLOAD_CHECK") { 30 }.to_i
|
86
|
-
MAX_UPLOAD_STATUS_CHECKS = ENV.fetch("MAX_UPLOAD_STATUS_CHECKS") { 100 }.to_i
|
87
104
|
# Good ol' loop-and-sleep. Haven't loop do'd in a while
|
88
105
|
def wait_for_media_to_upload!(url, container_id, config, options)
|
89
106
|
wait_attempts = 0
|
90
107
|
loop do
|
91
108
|
if wait_attempts > MAX_UPLOAD_STATUS_CHECKS
|
92
109
|
warn "Giving up waiting for media to upload after waiting #{SECONDS_PER_UPLOAD_CHECK * MAX_UPLOAD_STATUS_CHECKS} seconds: #{url}"
|
93
|
-
|
110
|
+
raise FacebookSucksAtDownloadingFilesError
|
94
111
|
end
|
95
112
|
|
96
113
|
res = Http.get("/#{container_id}", {
|
data/lib/feed2gram/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: feed2gram
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Searls
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
77
|
- !ruby/object:Gem::Version
|
78
78
|
version: '0'
|
79
79
|
requirements: []
|
80
|
-
rubygems_version: 3.5.
|
80
|
+
rubygems_version: 3.5.6
|
81
81
|
signing_key:
|
82
82
|
specification_version: 4
|
83
83
|
summary: Reads an Atom feed and posts its entries to Instagram
|