Skip to content

Commit

Permalink
facebook: add screenshots logging
Browse files Browse the repository at this point in the history
  • Loading branch information
naisanzaa committed Nov 14, 2023
1 parent 2f7cb50 commit fcbbe3c
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion automon/integrations/facebook/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def content_unavailable(self):
session=session,
stacktrace=stacktrace,
)))
self.screenshot_error()

log.debug(self._content_unavailable)
return self._content_unavailable
Expand All @@ -122,6 +123,7 @@ def creation_date(self):
session=session,
stacktrace=stacktrace,
)))
self.screenshot_error()

log.debug(self._creation_date)
return self._creation_date
Expand Down Expand Up @@ -150,6 +152,7 @@ def history(self):
session=session,
stacktrace=stacktrace,
)))
self.screenshot_error()

log.debug(self._history)
return self._history
Expand All @@ -170,6 +173,7 @@ def temporarily_blocked(self):
session=session,
stacktrace=stacktrace,
)))
self.screenshot_error()

log.debug(self._temporarily_blocked)
return self._temporarily_blocked
Expand All @@ -192,6 +196,7 @@ def members(self):
session=session,
stacktrace=stacktrace,
)))
self.screenshot_error()

log.debug(self._members)
return self._members
Expand Down Expand Up @@ -226,6 +231,7 @@ def must_login(self):
session=session,
stacktrace=stacktrace,
)))
self.screenshot_error()

log.debug(self._must_login)
return self._must_login
Expand All @@ -247,6 +253,7 @@ def posts_monthly(self):
session=session,
stacktrace=stacktrace,
)))
self.screenshot_error()

log.debug(self._posts_monthly)
return self._posts_monthly
Expand Down Expand Up @@ -282,6 +289,7 @@ def posts_today(self):
session=session,
stacktrace=stacktrace,
)))
self.screenshot_error()

log.debug(self._posts_today)
return self._posts_today
Expand Down Expand Up @@ -317,6 +325,7 @@ def privacy(self):
session=session,
stacktrace=stacktrace,
)))
self.screenshot_error()

log.debug(self._privacy)
return self._privacy
Expand All @@ -338,6 +347,7 @@ def privacy_details(self):
session=session,
stacktrace=stacktrace,
)))
self.screenshot_error()

log.debug(self._privacy_details)
return self._privacy_details
Expand All @@ -359,6 +369,7 @@ def title(self) -> str:
session=session,
stacktrace=stacktrace,
)))
self.screenshot_error()

log.debug(self._title)
return self._title
Expand Down Expand Up @@ -393,6 +404,7 @@ def visible(self) -> str:
session=session,
stacktrace=stacktrace,
)))
self.screenshot_error()

log.debug(self._visible)
return self._visible
Expand Down Expand Up @@ -422,6 +434,7 @@ def get(self, url: str) -> bool:
url=url,
result=result,
)))
self.screenshot()
return result

def get_about(self, rate_limiting: bool = True):
Expand All @@ -437,6 +450,7 @@ def get_about(self, rate_limiting: bool = True):
url=url,
result=result,
)))
self.screenshot()
return result

def get_with_rate_limiter(
Expand All @@ -461,11 +475,13 @@ def get_with_rate_limiter(
else:
self.rate_limit_decrease()
log.info(f'{result}')
self.screenshot_success()
return result

retry = retry + 1

log.error(f'{url}')
self.screenshot_error()
return result

def rate_limit_decrease(self, multiplier: int = 0.4):
Expand Down Expand Up @@ -494,9 +510,11 @@ def rate_limited(self):
"""rate limit checker"""
if self.temporarily_blocked() or self.must_login():
log.info(True)
self.screenshot_error()
return True

log.error(False)
self.screenshot_error()
return False

def run(self):
Expand All @@ -512,6 +530,23 @@ def restart(self):
log.info(f'{self._browser}')
return self.start()

def screenshot(self, filename: str = 'screenshot.png'):
screenshot = self._browser.save_screenshot(filename=filename, folder='.')
log.info(f'{screenshot}')
return screenshot

def screenshot_error(self):
"""get error screenshot"""
screenshot = self.screenshot(filename='error.png')
log.info(f'{screenshot}')
return screenshot

def screenshot_success(self):
"""get success screenshot"""
screenshot = self.screenshot(filename='success.png')
log.info(f'{screenshot}')
return screenshot

def set_url(self, url: str) -> str:
"""set new url"""
self._url = url
Expand All @@ -523,6 +558,7 @@ def start(self, headless: bool = True, random_user_agent: bool = False, set_user

if headless:
self._browser.set_webdriver().Chrome().in_headless().set_locale_experimental()
# self._browser.set_webdriver().Chrome().enable_headless().set_locale_experimental()
else:
self._browser.set_webdriver().Chrome().set_locale_experimental()

Expand All @@ -538,7 +574,9 @@ def start(self, headless: bool = True, random_user_agent: bool = False, set_user
log.info(str(dict(
browser=self._browser
)))
return self._browser.run()
browser = self._browser.run()
self._browser.set_webdriver().Chrome().set_window_size(width=1920 * 0.6, height=1080)
return browser

def stop(self):
"""alias to quit"""
Expand Down

0 comments on commit fcbbe3c

Please sign in to comment.