fuck_facebook 0.1.2 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f671ef4b3c5a7c3f2e6588e97c23047de204f309c06b0d563e239ad4f654ca8
4
- data.tar.gz: 94d1962dbc7d824bca10f51fb08f3388cd33f482f41f49afeed09fd80b77a325
3
+ metadata.gz: fd816f264c73ea38c4349c8110cade9787ae11f92de9b37ad8a1f6fbef9b2059
4
+ data.tar.gz: e2862a3aee723788f459ab7b84acf84ca2b3bda8ef6176e51a1018915cb350d7
5
5
  SHA512:
6
- metadata.gz: f2c7745e2ed0559bce742015e66e4203e254404badf0402a57deef1289496f6775e2c73766968779630a3c3a08a19ba270a8fd34c7c4b5846c1227d29074fcf6
7
- data.tar.gz: ae7dcdd2c32cac29858da002a0a13c16eaeff59bbe2e1734732aeee7022128d461ac12f8aa564e23f67ce4501c9d722a8dc324869b44d14ee62f100e80a711aa
6
+ metadata.gz: aa5dfc850834b1ab4efd759eb853ac2bdc25c6a9cb739ee704b2e2182fc917fc43b85c504c75ad7394074f0549abd8e372906911a68da64ea0a4c78766d0d39b
7
+ data.tar.gz: 8ebea4e69e013d5c2f7f7345755c5ed39768bdbcd231587ae06c64e196e718d2f57293ea9714c84cf61008bc104d05c1dfd90df7548c8eade979d76a5391f129
@@ -1,3 +1,3 @@
1
1
  module FuckFacebook
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.2.1'.freeze
3
3
  end
data/src/authenticator.rb CHANGED
@@ -19,7 +19,7 @@ class Authenticator
19
19
 
20
20
  accept_cookies
21
21
  submit_credentials
22
- submit_2fa
22
+ submit_otp
23
23
  click_remember_password
24
24
  end
25
25
 
@@ -32,7 +32,7 @@ class Authenticator
32
32
 
33
33
  def click_remember_password
34
34
  driver.navigate.to('https://www.facebook.com/settings?tab=security')
35
- driver.switch_to.frame(xpaths.element(:settings, :security_iframe))
35
+ driver.switch_to.frame(xpaths.wait_for_element(:settings, :security_iframe))
36
36
  xpaths.element(:settings, :save_login_information_edit_button).click
37
37
  xpaths.element(:settings, :save_login_information_button).click
38
38
  end
@@ -43,15 +43,20 @@ class Authenticator
43
43
  xpaths.element(:login_button).click
44
44
  end
45
45
 
46
- def submit_2fa
47
- return unless xpaths.element(:checkpoint, :prompt).text == 'Two-factor authentication required'
46
+ def submit_otp
47
+ return unless xpaths.element_exists?(:checkpoint, :otp_prompt)
48
48
 
49
49
  xpaths.element(:checkpoint, :otp_input).send_keys(user_input.get(:otp))
50
- xpaths.element(:checkpoint, :otp_continue_button).click
51
- xpaths.element(:checkpoint, :save_browser_continue_button).click
50
+ otp_button = xpaths.element(:checkpoint, :submit_button)
51
+ otp_button.click
52
+
53
+ save_browser_button = xpaths.element(:checkpoint, :submit_button)
54
+ save_browser_button.click
52
55
  end
53
56
 
54
57
  def accept_cookies
58
+ return unless xpaths.element_exists?(:accept_cookies_button)
59
+
55
60
  accept_cookies_button = xpaths.element(:accept_cookies_button)
56
61
  accept_cookies_button.click
57
62
  end
data/src/config.rb CHANGED
@@ -1,10 +1,24 @@
1
1
  require 'yaml'
2
2
 
3
3
  class Config
4
- CONFIG = YAML.load_file("#{ENV['HOME']}/.config/fuck-facebook/config.yaml")
4
+ CONFIG_FILE_PATH = "#{ENV['HOME']}/.local/share/fuck-facebook/config.yaml".freeze
5
5
 
6
6
  def self.option(*path)
7
7
  path_strings = path.map(&:to_s)
8
- CONFIG.dig(*path_strings)
8
+ config.dig(*path_strings)
9
+ end
10
+
11
+ private
12
+
13
+ def self.config
14
+ create_config_file_if_not_exists!
15
+
16
+ YAML.load_file(CONFIG_FILE_PATH)
17
+ end
18
+
19
+ def self.create_config_file_if_not_exists!
20
+ dirname = File.dirname(CONFIG_FILE_PATH)
21
+ FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
22
+ File.write(CONFIG_FILE_PATH, '{}') unless File.exist?(CONFIG_FILE_PATH)
9
23
  end
10
24
  end
@@ -41,7 +41,7 @@ class CookieHandler
41
41
  saved_cookies = JSON.parse(File.read(cookies_filename), symbolize_names: true)
42
42
 
43
43
  saved_cookies.each do |saved_cookie|
44
- saved_cookie[:expires] = Time.parse(saved_cookie[:expires])
44
+ saved_cookie[:expires] = Time.parse(saved_cookie[:expires]) unless saved_cookie[:expires].nil?
45
45
  end
46
46
 
47
47
  saved_cookies
@@ -18,10 +18,7 @@ class MessageHandler
18
18
  def messages
19
19
  visit_messages_page
20
20
 
21
- xpaths.wait_for_element(:messages, :chats)
22
-
23
- chats = xpaths.elements(:messages, :chats)
24
-
21
+ chats = xpaths.wait_for_elements(:messages, :chats)
25
22
  messages = messages_for_chats(chats)
26
23
 
27
24
  messages_after_last_message_time(messages)
data/src/xpaths.rb CHANGED
@@ -63,6 +63,12 @@ class Xpaths
63
63
  found_element
64
64
  end
65
65
 
66
+ def wait_for_elements(*path_elements)
67
+ wait_for_element(*path_elements)
68
+
69
+ elements(*path_elements)
70
+ end
71
+
66
72
  def for(*path_elements)
67
73
  path_elements_strings = path_elements.map(&:to_s)
68
74
  result = XPATHS.dig(*path_elements_strings)
data/xpaths.yaml CHANGED
@@ -8,13 +8,12 @@ settings:
8
8
  save_login_information_button: '//div[text() = "Save your login information"]'
9
9
  link_to_profile: '//a[@href="/me/"]'
10
10
  checkpoint:
11
- otp_input: '/html/body/div[1]/div[3]/div[1]/div/form/div/div[2]/div[3]/span/input'
12
- otp_continue_button: '/html/body/div[1]/div[3]/div[1]/div/form/div/div[3]/div[1]/button'
11
+ otp_prompt: '//strong[text() = "Two-factor authentication required"]'
12
+ otp_input: '//*[@id="approvals_code"]'
13
13
  save_browser_radio_input: '/html/body/div[1]/div[3]/div[1]/div/form/div/div[2]/div[2]/div[1]/input'
14
- save_browser_continue_button: '/html/body/div[1]/div[3]/div[1]/div/form/div/div[3]/div[1]/button'
15
- prompt: '/html/body/div[1]/div[3]/div[1]/div/form/div/div[1]'
14
+ submit_button: '//*[@id="checkpointSubmitButton"]'
16
15
  messages:
17
- chats: '/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div[1]/div/div/div/div[3]/div[1]/div[2]/div/child::*[@role = "row"]'
16
+ chats: './/*[@aria-label="Chats"]/child::*'
18
17
  title_relative: 'div[1]/div/a/div/div[2]/div[1]/div/div/div[1]/span/span/span/span'
19
18
  text_relative: 'div[1]/div/a/div/div[2]/div[1]/div/div/div[2]/span/span/div/span[1]/span'
20
19
  time_sent_ago_relative: 'div[1]/div/a/div/div[2]/div[1]/div/div/div[2]/span/span/div/span[3]'
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.1.2
4
+ version: 0.2.1
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-07-15 00:00:00.000000000 Z
11
+ date: 2021-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport