reddit-to-telegram 0.1.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +54 -3
- data/lib/reddit-to-telegram.rb +1 -0
- data/lib/reddit_to_telegram/store/temp_file.rb +8 -5
- data/lib/reddit_to_telegram/telegram/prepare_request.rb +1 -1
- data/lib/reddit_to_telegram/telegram/video.rb +12 -6
- data/lib/reddit_to_telegram/vars.rb +8 -0
- data/lib/reddit_to_telegram/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ec45bcf41a275baa3ea712968010d520b4af973a78149837ebe4cbc0b4c3870
|
4
|
+
data.tar.gz: 328805f68a80798c6c9c3a26fbd00aac37560ac97d55b601df9471b0587c2a31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7184c7bddf2027cfef0bd40ddd90a044e309482b1467d1ab942114d43d4b6c4b7c03d2081a06035ba4b408d82aa19c64ba28d74d5ef98c03f58399153e61dbe3
|
7
|
+
data.tar.gz: e46c030bd186fbef1185970769d8d9263849e2b8048c043ca5b7ffa28c9a5b7d4e980fde260ee705ae2358419c7c581ebba458e620c68c3742541bc511dbdaae
|
data/README.md
CHANGED
@@ -4,7 +4,58 @@
|
|
4
4
|
|
5
5
|
#### Fetches hot posts from chosen subreddits and pushes them to Telegram channels.
|
6
6
|
|
7
|
-
|
7
|
+
Beware, this is remotely not production-ready, you'll see lots of bugs and it may break at any time.
|
8
|
+
Be sure to check for gem updates.
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
## Installation
|
11
|
+
In your `Gemfile` add:
|
12
|
+
```
|
13
|
+
gem "reddit-to-telegram"
|
14
|
+
```
|
15
|
+
Then run `bundle install`.
|
16
|
+
|
17
|
+
Or `gem install reddit-to-telegram`, but don't forget to `require` it first then.
|
18
|
+
|
19
|
+
## Prerequisites
|
20
|
+
- You need an AWS account to host a free SimpleDB (memory and local file storage options are available, but no way to switch for now)
|
21
|
+
- (Optionally) Create a Reddit app, which would allow more requests to reddit
|
22
|
+
- [Obtain](https://core.telegram.org/bots/tutorial#obtain-your-bot-token) a telegram bot token
|
23
|
+
|
24
|
+
## Installation
|
25
|
+
To run it, you'll need some env variables set.
|
26
|
+
```
|
27
|
+
RTT_AWS_ACCESS_KEY_ID= # Your AWS access key ID. Needed for AWS SimpleDB storage.
|
28
|
+
RTT_AWS_REGION= # AWS region your SimpleDB will be hosted on. Beware, it's not available in all regions.
|
29
|
+
RTT_AWS_SECRET_ACCESS_KEY= # Your AWS access key ID. Needed for AWS SimpleDB storage.
|
30
|
+
RTT_MAX_STORED_POSTS= # (Optional) Number of posts to store in the database to avoid duplicates, default is 25.
|
31
|
+
RTT_REDDIT_CLIENT_ID= # Reddit app credentials to access API. Might not be needed depending on setup, reddit allows some requests without authentication.
|
32
|
+
RTT_REDDIT_CLIENT_SECRET= # Reddit app credentials to access API. Might not be needed depending on setup, reddit allows some requests without authentication.
|
33
|
+
RTT_TELEGRAM_BOT_TOKEN= # The token you've received when you've created a telegram bot.
|
34
|
+
RTT_TEMP_DIR= (Optional) # Directory to write temp files to without trailing /
|
35
|
+
```
|
36
|
+
|
37
|
+
You can also set them dynamically:
|
38
|
+
```
|
39
|
+
RedditToTelegram::Vars.assign_values(
|
40
|
+
max_stored_posts:,
|
41
|
+
tmp_dir:
|
42
|
+
aws_access_key_id:,
|
43
|
+
aws_secret_access_key:,
|
44
|
+
aws_region:,
|
45
|
+
reddit_client_id:,
|
46
|
+
reddit_client_secret:,
|
47
|
+
telegram_bot_token:
|
48
|
+
)
|
49
|
+
```
|
50
|
+
## Usage
|
51
|
+
|
52
|
+
1. Add the bot as administrator to Telegram channels you'd like to post to.
|
53
|
+
2.
|
54
|
+
```
|
55
|
+
RedditToTelegram.post(
|
56
|
+
subreddit_name_1: :telegram_channel_id_1,
|
57
|
+
subreddit_name_2: :telegram_channel_id_2
|
58
|
+
)
|
59
|
+
|
60
|
+
```
|
61
|
+
Use `:telegram_channel_id` without the `@`.
|
data/lib/reddit-to-telegram.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "json"
|
4
|
+
require_relative "../vars"
|
4
5
|
|
5
6
|
module RedditToTelegram
|
6
7
|
module Store
|
7
8
|
class TempFile
|
8
|
-
STORE_FILE_DIR = "#{Dir.pwd}/tmp/store.json".freeze
|
9
|
-
|
10
9
|
class << self
|
11
10
|
attr_reader :reddit_token, :posts
|
12
11
|
|
@@ -36,9 +35,9 @@ module RedditToTelegram
|
|
36
35
|
end
|
37
36
|
|
38
37
|
def read_file
|
39
|
-
return assign_default_values unless File.exist?(
|
38
|
+
return assign_default_values unless File.exist?(temp_file_path)
|
40
39
|
|
41
|
-
file = File.read(
|
40
|
+
file = File.read(temp_file_path)
|
42
41
|
data = JSON.parse(file)
|
43
42
|
@reddit_token = data["reddit_token"]
|
44
43
|
@posts = {}
|
@@ -52,13 +51,17 @@ module RedditToTelegram
|
|
52
51
|
@posts.each do |subreddit, values|
|
53
52
|
data["posts_#{subreddit}".to_sym] = values
|
54
53
|
end
|
55
|
-
File.open(
|
54
|
+
File.open(temp_file_path, "w") { |f| f.write(data.to_json) }
|
56
55
|
end
|
57
56
|
|
58
57
|
def assign_default_values
|
59
58
|
@reddit_token = nil
|
60
59
|
@posts = {}
|
61
60
|
end
|
61
|
+
|
62
|
+
def temp_file_path
|
63
|
+
"#{Vars.tmp_dir}/store.json"
|
64
|
+
end
|
62
65
|
end
|
63
66
|
end
|
64
67
|
end
|
@@ -1,23 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "open-uri"
|
4
|
+
require_relative "../vars"
|
4
5
|
|
5
6
|
module RedditToTelegram
|
6
7
|
module Telegram
|
7
8
|
class Video
|
8
|
-
TEMP_VIDEO_PATH = "#{Dir.pwd}/tmp/video.mp4".freeze
|
9
|
-
|
10
9
|
class << self
|
11
10
|
def from_link(link)
|
12
11
|
download = URI.parse(link).open
|
13
|
-
|
12
|
+
File.open(temp_video_path, "w+b") do |file|
|
13
|
+
download.respond_to?(:read) ? IO.copy_stream(download, file) : file.write(download)
|
14
|
+
end
|
14
15
|
end
|
15
16
|
|
16
17
|
def delete_file
|
17
|
-
|
18
|
-
|
18
|
+
return unless File.exist?(temp_video_path)
|
19
|
+
|
20
|
+
f = File.open(temp_video_path, "r")
|
19
21
|
f.close unless f.nil? || f.closed?
|
20
|
-
File.delete(
|
22
|
+
File.delete(temp_video_path)
|
23
|
+
end
|
24
|
+
|
25
|
+
def temp_video_path
|
26
|
+
"#{Vars.tmp_dir}/video.mp4"
|
21
27
|
end
|
22
28
|
end
|
23
29
|
end
|
@@ -2,10 +2,13 @@
|
|
2
2
|
|
3
3
|
module RedditToTelegram
|
4
4
|
module Vars
|
5
|
+
DEFAULT_TMP_DIR = "#{Dir.pwd}/tmp".freeze
|
6
|
+
|
5
7
|
class << self
|
6
8
|
# rubocop:disable Metrics/ParameterLists
|
7
9
|
def assign_values(
|
8
10
|
max_stored_posts:,
|
11
|
+
tmp_dir:,
|
9
12
|
aws_access_key_id:,
|
10
13
|
aws_secret_access_key:,
|
11
14
|
aws_region:,
|
@@ -15,6 +18,7 @@ module RedditToTelegram
|
|
15
18
|
)
|
16
19
|
|
17
20
|
@max_stored_posts = max_stored_posts
|
21
|
+
@tmp_dir = tmp_dir
|
18
22
|
AWS.instance_variable_set(:@access_key_id, aws_access_key_id)
|
19
23
|
AWS.instance_variable_set(:@secret_access_key, aws_secret_access_key)
|
20
24
|
AWS.instance_variable_set(:@region, aws_region)
|
@@ -27,6 +31,10 @@ module RedditToTelegram
|
|
27
31
|
def max_stored_posts
|
28
32
|
@max_stored_posts ||= ENV["RTT_MAX_STORED_POSTS"].to_i || 25
|
29
33
|
end
|
34
|
+
|
35
|
+
def tmp_dir
|
36
|
+
@tmp_dir ||= ENV["RTT_TEMP_DIR"] || DEFAULT_TMP_DIR
|
37
|
+
end
|
30
38
|
end
|
31
39
|
|
32
40
|
class AWS
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reddit-to-telegram
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Tityuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01-
|
11
|
+
date: 2024-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-simpledb
|