committed by
GitHub
5 changed files with 75 additions and 39 deletions
@ -1,50 +1,59 @@ |
|||||
from selenium.common.exceptions import (NoSuchElementException, |
import json |
||||
StaleElementReferenceException, |
import os |
||||
TimeoutException) |
|
||||
from time import sleep |
|
||||
from json import dumps |
|
||||
from os.path import abspath, relpath, split |
from os.path import abspath, relpath, split |
||||
from os import environ |
import time |
||||
|
|
||||
SELENIUM_EXCEPTIONS = (NoSuchElementException, |
from selenium.common.exceptions import ( |
||||
StaleElementReferenceException, |
NoSuchElementException, |
||||
TimeoutException) |
StaleElementReferenceException, |
||||
|
TimeoutException |
||||
|
) |
||||
|
|
||||
|
|
||||
|
SELENIUM_EXCEPTIONS = ( |
||||
|
NoSuchElementException, |
||||
|
StaleElementReferenceException, |
||||
|
TimeoutException |
||||
|
) |
||||
|
|
||||
def try_move(actions, el): |
def try_move(actions, el): |
||||
for _ in range(10): |
for _ in range(10): |
||||
try: |
try: |
||||
actions.move_to_element(el).perform() |
actions.move_to_element(el).perform() |
||||
except StaleElementReferenceException: |
except StaleElementReferenceException: |
||||
sleep(5) |
time.sleep(5) |
||||
continue |
continue |
||||
|
|
||||
|
|
||||
def archiver(category): |
def archiver(category): |
||||
""" |
""" |
||||
category: the category of logs you want to log |
Log content to file. Call using `archive("some content")` |
||||
return values: (log_file_handle, archiver) |
|
||||
|
Args: |
||||
|
category: str The category of logs you want to log |
||||
|
|
||||
call archiver like archive("some content") |
Returns: |
||||
|
(log_file_handle, archiver) |
||||
""" |
""" |
||||
log_path = "{0}.log".format(abspath(relpath(split(category)[-1], "."))) |
log_path = "{0}.log".format(abspath(relpath(split(category)[-1], "."))) |
||||
|
|
||||
log_file = open(log_path, mode="ta", buffering=1) |
log_file = open(log_path, mode="ta", buffering=1) |
||||
|
|
||||
def log(content, timestamp=False): |
def log(content, timestamp=False): |
||||
if environ.get("DELETEFB_ARCHIVE", "true") == "false": |
if os.environ.get("DELETEFB_ARCHIVE", "true") == "false": |
||||
return |
return |
||||
structured_content = { |
structured_content = { |
||||
"category" : category, |
"category" : category, |
||||
"content" : content, |
"content" : content, |
||||
"timestamp" : timestamp |
"timestamp" : timestamp |
||||
} |
} |
||||
|
|
||||
log_file.write("{0}\n".format(dumps(structured_content))) |
log_file.write("{0}\n".format(json.dumps(structured_content))) |
||||
|
|
||||
return (log_file, log) |
return (log_file, log) |
||||
|
|
||||
|
|
||||
no_chrome_driver = """ |
NO_CHROME_DRIVER = """ |
||||
You need to install the chromedriver for Selenium\n |
You need to install the chromedriver for Selenium\n |
||||
Please see this link https://github.com/weskerfoot/DeleteFB#how-to-use-it\n |
Please see this link https://github.com/weskerfoot/DeleteFB#how-to-use-it\n |
||||
""" |
""" |
||||
|
Loading…
Reference in new issue