fuck_facebook 0.4.0 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gemfile.lock +1 -1
- data/README.md +3 -0
- data/bin/fuck-facebook +3 -2
- data/lib/fuck_facebook/version.rb +1 -1
- data/src/config.rb +27 -7
- data/src/error_reporter.rb +40 -2
- data/src/message_handler.rb +4 -5
- data/src/senders/email.rb +2 -1
- data/src/senders/stdout.rb +6 -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: acfe1137400e4f4cc8fc79f7d0222eb8617eb72032fade8f975da0c638967a7a
|
4
|
+
data.tar.gz: ef0b084adbf6017d96b008792efc158bde131df714bbc9382738394bcbf01462
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf839aa8b6b7b0803588021a3d444e6ef641240569a0ed72a98eed6a66f9a123498a8891c1c25218ea47bb005110d64861acb1a277b553f096ced32d40b50c1c
|
7
|
+
data.tar.gz: ad427fa1ae23c9abf1c2d78db1b547c7f4cc73ce0b12dbefc57c443a5ac2fd7812924c543fb60d1159fe5e421dc0442d6c0ef7fc8e846c6863c4687d3e36fe29
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -26,6 +26,9 @@ This way if you have emails going out for new messages, you won't get notified f
|
|
26
26
|
Here's a complete config file along with an explanation of each option:
|
27
27
|
|
28
28
|
```yaml
|
29
|
+
errors:
|
30
|
+
min_minutes_between_reports: 0 # Only report error if one has not occured in the past X minutes
|
31
|
+
include_screenshot: false # Generates a screenshot with the error report
|
29
32
|
smtp:
|
30
33
|
from_email: sender@example.com
|
31
34
|
to_email: receiver@example.com
|
data/bin/fuck-facebook
CHANGED
@@ -12,11 +12,12 @@ require_relative '../src/message_sender'
|
|
12
12
|
require_relative '../src/error_reporter'
|
13
13
|
|
14
14
|
options = ArgsParser.parse_args
|
15
|
+
facebook_connection = nil
|
15
16
|
|
16
17
|
begin
|
18
|
+
facebook_connection = FacebookConnection.new(headless: options[:headless])
|
17
19
|
raise 'Error triggered by --simulate-error flag' if options[:simulate_error]
|
18
20
|
|
19
|
-
facebook_connection = FacebookConnection.new(headless: options[:headless])
|
20
21
|
facebook_connection.cookie_handler.clear! if options[:clear_cookies]
|
21
22
|
facebook_connection.login if options[:login]
|
22
23
|
message_sender = MessageSender.new(options[:sender], facebook_connection)
|
@@ -24,5 +25,5 @@ begin
|
|
24
25
|
message_sender.send_messages if options[:messages]
|
25
26
|
facebook_connection.close
|
26
27
|
rescue StandardError => e
|
27
|
-
ErrorReporter.report_error(options[:sender], e)
|
28
|
+
ErrorReporter.report_error(options[:sender], e, facebook_connection: facebook_connection)
|
28
29
|
end
|
data/src/config.rb
CHANGED
@@ -3,15 +3,16 @@ require 'yaml'
|
|
3
3
|
class Config
|
4
4
|
CONFIG_FILE_PATH = "#{ENV['HOME']}/.local/share/fuck-facebook/config.yaml".freeze
|
5
5
|
|
6
|
-
def self.option(*path)
|
6
|
+
def self.option(*path, default: nil, type: nil)
|
7
7
|
env_var = "FF_#{path.join('_').upcase}"
|
8
|
-
return ENV[env_var] if ENV[env_var]
|
9
|
-
|
10
8
|
path_strings = path.map(&:to_s)
|
11
|
-
config.dig(*path_strings)
|
12
|
-
end
|
13
9
|
|
14
|
-
|
10
|
+
value = config.dig(*path_strings)
|
11
|
+
value = ENV[env_var] if ENV[env_var]
|
12
|
+
value = default if value.nil?
|
13
|
+
|
14
|
+
cast_value_to_type(value, type)
|
15
|
+
end
|
15
16
|
|
16
17
|
def self.config
|
17
18
|
create_config_file_if_not_exists!
|
@@ -19,9 +20,28 @@ class Config
|
|
19
20
|
YAML.load_file(CONFIG_FILE_PATH)
|
20
21
|
end
|
21
22
|
|
22
|
-
def self.create_config_file_if_not_exists!
|
23
|
+
private_class_method def self.create_config_file_if_not_exists!
|
23
24
|
dirname = File.dirname(CONFIG_FILE_PATH)
|
24
25
|
FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
|
25
26
|
File.write(CONFIG_FILE_PATH, '{}') unless File.exist?(CONFIG_FILE_PATH)
|
26
27
|
end
|
28
|
+
|
29
|
+
private_class_method def self.cast_value_to_type(value, type)
|
30
|
+
case type
|
31
|
+
when nil
|
32
|
+
value
|
33
|
+
when :boolean
|
34
|
+
cast_value_to_boolean(value)
|
35
|
+
when :float
|
36
|
+
value.to_f
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private_class_method def self.cast_value_to_boolean(value)
|
41
|
+
if [true, false].include?(value)
|
42
|
+
value
|
43
|
+
elsif value.is_a?(String)
|
44
|
+
value == 'true'
|
45
|
+
end
|
46
|
+
end
|
27
47
|
end
|
data/src/error_reporter.rb
CHANGED
@@ -1,6 +1,44 @@
|
|
1
1
|
class ErrorReporter
|
2
|
-
def self.report_error(sender_name, error)
|
3
|
-
|
2
|
+
def self.report_error(sender_name, error, facebook_connection: nil)
|
3
|
+
raise error unless report_error?
|
4
|
+
|
5
|
+
screenshot = include_screenshot?(facebook_connection) ? create_screenshot(facebook_connection) : nil
|
6
|
+
|
7
|
+
Senders.by_name(sender_name).send_error(error, screenshot: screenshot)
|
8
|
+
|
9
|
+
Storage.set(:last_error_reported_time, Time.now)
|
4
10
|
raise error
|
5
11
|
end
|
12
|
+
|
13
|
+
private_class_method def self.include_screenshot?(facebook_connection)
|
14
|
+
include_screenshot_config = Config.option(
|
15
|
+
:errors,
|
16
|
+
:include_screenshot,
|
17
|
+
default: false,
|
18
|
+
type: :boolean
|
19
|
+
)
|
20
|
+
|
21
|
+
include_screenshot_config && facebook_connection.present?
|
22
|
+
end
|
23
|
+
|
24
|
+
private_class_method def self.create_screenshot(facebook_connection)
|
25
|
+
facebook_connection.driver.screenshot_as(:png)
|
26
|
+
rescue StandardError
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
|
30
|
+
private_class_method def self.report_error?
|
31
|
+
min_minutes_between_reports = Config.option(
|
32
|
+
:errors,
|
33
|
+
:min_minutes_between_reports,
|
34
|
+
default: 0,
|
35
|
+
type: :float
|
36
|
+
)
|
37
|
+
|
38
|
+
last_error_reported_time = Storage.get(:last_error_reported_time, default: Time.new(2000))
|
39
|
+
|
40
|
+
next_report_time = last_error_reported_time + min_minutes_between_reports.minutes
|
41
|
+
|
42
|
+
Time.now > next_report_time
|
43
|
+
end
|
6
44
|
end
|
data/src/message_handler.rb
CHANGED
@@ -53,13 +53,12 @@ class MessageHandler
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def messages_after_last_message_time(messages)
|
56
|
-
|
56
|
+
last_message_check_time = Storage.get(:last_message_check_time, default: Time.new(2004, 2, 4))
|
57
|
+
last_check_time_with_buffer = last_message_check_time - 5.minutes
|
57
58
|
|
58
|
-
messages_to_return = messages.select { _1.timestamp >
|
59
|
+
messages_to_return = messages.select { _1.timestamp > last_check_time_with_buffer }
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
Storage.set(:last_message_time, last_message_time)
|
61
|
+
Storage.set(:last_message_check_time, Time.now)
|
63
62
|
|
64
63
|
messages_to_return
|
65
64
|
end
|
data/src/senders/email.rb
CHANGED
@@ -11,12 +11,13 @@ module Senders
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def self.send_error(error)
|
14
|
+
def self.send_error(error, screenshot: nil)
|
15
15
|
Mail.deliver do
|
16
16
|
from Config.option(:smtp, :from_email)
|
17
17
|
to Config.option(:smtp, :to_email)
|
18
18
|
subject 'Error occurred during Fuck Facebook command'
|
19
19
|
body error.full_message(highlight: false)
|
20
|
+
add_file filename: 'error_screenshot.png', content: screenshot if screenshot
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
data/src/senders/stdout.rb
CHANGED
@@ -6,8 +6,13 @@ module Senders
|
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
-
def self.send_error(error)
|
9
|
+
def self.send_error(error, screenshot: nil)
|
10
10
|
puts error
|
11
|
+
return if screenshot.nil?
|
12
|
+
|
13
|
+
filename = "fuck_facebook_error_#{Time.now.iso8601}.png"
|
14
|
+
File.write(filename, screenshot)
|
15
|
+
puts "Screenshot of error page saved as #{filename}"
|
11
16
|
end
|
12
17
|
end
|
13
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fuck_facebook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keeyan Nejad
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|