reddit-to-telegram 0.1.2 → 0.2.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 +4 -4
- data/README.md +55 -2
- 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 +10 -5
- 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: 36d1523dfcd1455f13aaf69a3460c86c588dc51a318c956bcaa25acbbee0cd82
|
4
|
+
data.tar.gz: b5d4d20eedf4a41ffec66d26479955627e205c944696ef445e539e1bb2d9d2a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51f3e8460aa53bb0d028e27b9852d9a23501a3fa4d6a886d382ae232d68d7a3fcf466c61af82fb38079eea4911fdb10cd830226b4bc4373b5a96426ce8e1378f
|
7
|
+
data.tar.gz: 04465e55387e6e5c96e1b891a0ea2189538b9b038e92c80c7a369f4e417092b0f6b2dba6411f9ad83405d9712b764c53b6ab6e207b9bc99d5dd3005823ca8ecb
|
data/README.md
CHANGED
@@ -4,7 +4,60 @@
|
|
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 and you'll see lots of bugs. Be sure to check for gem updates.
|
8
8
|
|
9
|
-
|
9
|
+
## Installation
|
10
|
+
In your `Gemfile` add:
|
11
|
+
```
|
12
|
+
gem "reddit-to-telegram"
|
13
|
+
```
|
14
|
+
Then run `bundle install`.
|
15
|
+
|
16
|
+
Or `gem install reddit-to-telegram`, but don't forget to `require` it first then.
|
17
|
+
|
18
|
+
## Prerequisites
|
19
|
+
- 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)
|
20
|
+
- (Optionally) Create a Reddit app, which would allow more requests to reddit
|
21
|
+
- [Obtain](https://core.telegram.org/bots/tutorial#create-your-project) a telegram bot token
|
22
|
+
|
23
|
+
## Installation
|
24
|
+
To run it, you'll need some env variables set.
|
25
|
+
```
|
26
|
+
RTT_AWS_ACCESS_KEY_ID= # Your AWS access key ID. Needed for AWS SimpleDB storage.
|
27
|
+
RTT_AWS_REGION= # AWS region your SimpleDB will be hosted on. Beware, it's on available in all regions.
|
28
|
+
RTT_AWS_SECRET_ACCESS_KEY= # Your AWS access key ID. Needed for AWS SimpleDB storage.
|
29
|
+
RTT_MAX_STORED_POSTS= # (Optional) Number of posts to store in the database to avoid duplicates, default is 25.
|
30
|
+
RTT_REDDIT_CLIENT_ID= # Reddit app credentials to access API. Might not be needed depending on setup, reddit allows some requests without authentication.
|
31
|
+
RTT_REDDIT_CLIENT_SECRET= # Reddit app credentials to access API. Might not be needed depending on setup, reddit allows some requests without authentication.
|
32
|
+
RTT_TELEGRAM_BOT_TOKEN= # The token you've received when you've created a telegram bot.
|
33
|
+
RTT_TEMP_DIR= (Optional) # Directory to write temp files to without trailing /
|
34
|
+
```
|
35
|
+
|
36
|
+
You can also set them dynamically:
|
37
|
+
```
|
38
|
+
RedditToTelegram::Vars.assign_values(
|
39
|
+
max_stored_posts:,
|
40
|
+
aws_access_key_id:,
|
41
|
+
aws_secret_access_key:,
|
42
|
+
aws_region:,
|
43
|
+
reddit_client_id:,
|
44
|
+
reddit_client_secret:,
|
45
|
+
telegram_bot_token:
|
46
|
+
)
|
47
|
+
```
|
48
|
+
## Usage
|
49
|
+
|
50
|
+
1. Add the bot as administrator to Telegram channels you'd like to post to.
|
51
|
+
2.
|
52
|
+
```
|
53
|
+
RedditToTelegram.post(
|
54
|
+
subreddit_name_1: :telegram_channel_id_1,
|
55
|
+
subreddit_name_2: :telegram_channel_id_2
|
56
|
+
)
|
57
|
+
|
58
|
+
```
|
59
|
+
Use `:telegram_channel_id` without the `@`.
|
60
|
+
|
61
|
+
## TODO
|
62
|
+
- Storage options
|
10
63
|
- Error handling (maybe send them to another channel in Telegram)
|
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,28 @@
|
|
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
|
-
f = File.open(
|
18
|
+
f = File.open(temp_video_path, "r")
|
18
19
|
ensure
|
19
20
|
f.close unless f.nil? || f.closed?
|
20
|
-
File.delete(
|
21
|
+
File.delete(temp_video_path) if File.exist?(temp_video_path)
|
22
|
+
end
|
23
|
+
|
24
|
+
def temp_video_path
|
25
|
+
"#{Vars.tmp_dir}/video.mp4"
|
21
26
|
end
|
22
27
|
end
|
23
28
|
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.
|
4
|
+
version: 0.2.0
|
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
|