Skip to content

Commit

Permalink
Add linter for python
Browse files Browse the repository at this point in the history
  • Loading branch information
jorbush committed Jun 6, 2024
1 parent e2ae7fc commit 534feb1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/autopep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Autopep8 Check

on:
push:
branches: main
pull_request:
branches: main

jobs:
autopep8-check:
name: Check Code Style with Autopep8
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.10.13

- name: Install dependencies
run: |
cd tools/web_scraper
python -m pip install --upgrade pip
pip install autopep8
- name: Check code style
run: |
cd tools/web_scraper
if autopep8 --recursive --exclude venv --diff . | grep -E '^\+'; then
echo "Code style issues found. Please run autopep8 to fix them."
exit 1
fi
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ format:
cargo fmt
cd deno && \
deno fmt
cd tools/web_scraper && source venv/bin/activate && autopep8 --recursive --exclude venv --in-place .

validium:
cd deno && \
Expand Down
2 changes: 2 additions & 0 deletions tools/web_scraper/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
attrs==23.2.0
autopep8==2.2.0
certifi==2024.6.2
h11==0.14.0
idna==3.7
outcome==1.3.0.post0
pycodestyle==2.11.1
PySocks==1.7.1
python-dotenv==1.0.1
selenium==4.21.0
Expand Down
14 changes: 12 additions & 2 deletions tools/web_scraper/web_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from selenium.webdriver.support.ui import WebDriverWait
from dotenv import load_dotenv


def load_environment_variables():
"""Load environment variables from the .env file."""
load_dotenv()
Expand All @@ -24,6 +25,7 @@ def load_environment_variables():
'smtp_password': os.getenv('SMTP_PASSWORD')
}


def setup_webdriver():
"""Configure the Selenium driver to work in headless mode."""
chrome_options = Options()
Expand All @@ -33,6 +35,7 @@ def setup_webdriver():
chrome_options.add_argument("--disable-dev-shm-usage")
return webdriver.Chrome(options=chrome_options)


def claim_avail(driver, address):
"""Perform the request to claim AVAIL."""
URL = "https://faucet.avail.tools/"
Expand All @@ -42,10 +45,12 @@ def claim_avail(driver, address):
driver.get(URL)

wait = WebDriverWait(driver, 10)
address_input = wait.until(EC.visibility_of_element_located((By.ID, ADDRESS_INPUT_TAG)))
address_input = wait.until(
EC.visibility_of_element_located((By.ID, ADDRESS_INPUT_TAG)))
address_input.send_keys(address)

button = wait.until(EC.element_to_be_clickable((By.XPATH, f"//button[text()='{BUTTON_TEXT}']")))
button = wait.until(EC.element_to_be_clickable(
(By.XPATH, f"//button[text()='{BUTTON_TEXT}']")))
button.click()

# Wait a moment for the toast message to appear
Expand All @@ -54,6 +59,7 @@ def claim_avail(driver, address):
page_source = driver.page_source
return page_source


def check_for_errors(page_source):
"""Check if there are error messages on the page."""
message = "Successfully claimed AVAIL!"
Expand All @@ -64,6 +70,7 @@ def check_for_errors(page_source):
logging.info(message)
return message


def send_email(subject, body, config):
"""Send an email with the given subject and body."""
msg = MIMEMultipart()
Expand All @@ -85,6 +92,7 @@ def send_email(subject, body, config):
except Exception as e:
logging.error(f"Failed to send email: {e}")


def setup_logging():
"""Set up logging to log events to a file."""
if not os.path.exists('logs'):
Expand All @@ -99,6 +107,7 @@ def setup_logging():
format='%(asctime)s - %(levelname)s - %(message)s'
)


def main():
setup_logging()
config = load_environment_variables()
Expand All @@ -118,5 +127,6 @@ def main():
driver.quit()
logging.info("Driver quit successfully.")


if __name__ == "__main__":
main()

0 comments on commit 534feb1

Please sign in to comment.