fuck_facebook 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58036357e5b5129b1f1d3395335e519c5fe361b888367f39b0aa22868ccafea2
4
- data.tar.gz: 75b470be6a7b43fb1b2f1169c76b94c0f36fa7dd16e7f407fd0c604b74e740ad
3
+ metadata.gz: 4444d134e1ae1d10b948ae6432691f99c1c22498aea2f0530359b0c93a1df967
4
+ data.tar.gz: b276c6b4a680c546b2b34366b5e28cd1af620ef7800ae7f2964bbded6235eff8
5
5
  SHA512:
6
- metadata.gz: 9a0b4111c0c2df0dc5fca7d154152b593e42a7f7bcf98eace36d4a85422a8786168c1b668b910b1e0187e9edbf683ae772f04aa1b471594702a7b6134d975b88
7
- data.tar.gz: 6fb6a161adbfc38a33af6a36f1c56dfa98fc8d0cc5b311b0783ded7cd9b7d9d5eec0badf12076bccec281f03e4e7a474031073cd24d3a6fd89c40596798ca32d
6
+ metadata.gz: 2e9a2254136c1886d20e7f164bbf1cf9d06d1a6191ed7522df717db580b6eea1b48f9ab5c9caebb9b84c75bc24f8467e0c92b30d5bae5f1131a99b7a6bb93b94
7
+ data.tar.gz: 5b930019d90be80fb751a487c2b71b0021278dc1952fd2a61baac57b7e88a4bcfc33be612699193bd6caeeb1c43a5fb0b7a231fce555d41c32e6d69a6cb93185
data/.gitignore CHANGED
@@ -11,3 +11,5 @@
11
11
  .rspec_status
12
12
 
13
13
  *.gem
14
+
15
+ fuck_facebook_error*.png
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fuck_facebook (0.4.0)
4
+ fuck_facebook (0.4.1)
5
5
  activesupport (~> 6.1)
6
6
  highline (~> 2.0)
7
7
  mail (~> 2.7)
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
@@ -1,3 +1,3 @@
1
1
  module FuckFacebook
2
- VERSION = '0.4.1'.freeze
2
+ VERSION = '0.5.0'.freeze
3
3
  end
data/src/config.rb CHANGED
@@ -3,15 +3,17 @@ 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)
7
7
  env_var = "FF_#{path.join('_').upcase}"
8
8
  return ENV[env_var] if ENV[env_var]
9
9
 
10
10
  path_strings = path.map(&:to_s)
11
- config.dig(*path_strings)
12
- end
11
+ value = config.dig(*path_strings)
12
+
13
+ return value if value
13
14
 
14
- private
15
+ default
16
+ end
15
17
 
16
18
  def self.config
17
19
  create_config_file_if_not_exists!
@@ -19,7 +21,7 @@ class Config
19
21
  YAML.load_file(CONFIG_FILE_PATH)
20
22
  end
21
23
 
22
- def self.create_config_file_if_not_exists!
24
+ private_class_method def self.create_config_file_if_not_exists!
23
25
  dirname = File.dirname(CONFIG_FILE_PATH)
24
26
  FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
25
27
  File.write(CONFIG_FILE_PATH, '{}') unless File.exist?(CONFIG_FILE_PATH)
@@ -1,6 +1,32 @@
1
1
  class ErrorReporter
2
- def self.report_error(sender_name, error)
3
- Senders.by_name(sender_name).send_error(error)
2
+ def self.report_error(sender_name, error, facebook_connection: nil)
3
+ raise error unless report_error?
4
+
5
+ Storage.set(:last_error_reported_time, Time.now)
6
+
7
+ screenshot = include_screenshot?(facebook_connection) ? create_screenshot(facebook_connection) : nil
8
+
9
+ Senders.by_name(sender_name).send_error(error, screenshot: screenshot)
4
10
  raise error
5
11
  end
12
+
13
+ private_class_method def self.include_screenshot?(facebook_connection)
14
+ Config.option(:errors, :include_screenshot) && facebook_connection.present?
15
+ end
16
+
17
+ private_class_method def self.create_screenshot(facebook_connection)
18
+ facebook_connection.driver.screenshot_as(:png)
19
+ rescue StandardError
20
+ nil
21
+ end
22
+
23
+ private_class_method def self.report_error?
24
+ min_minutes_between_reports = Config.option(:errors, :min_minutes_between_reports, default: 0)
25
+
26
+ last_error_reported_time = Storage.get(:last_error_reported_time, default: Time.new(2000))
27
+
28
+ next_report_time = last_error_reported_time + min_minutes_between_reports.minutes
29
+
30
+ Time.now > next_report_time
31
+ end
6
32
  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
@@ -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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fuck_facebook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keeyan Nejad