File size: 3,624 Bytes
22cf590 7f902f3 e0cf701 7f902f3 22cf590 e0cf701 7f902f3 e0cf701 7f902f3 e0cf701 7f902f3 e0cf701 7f902f3 e0cf701 7f902f3 e0cf701 7f902f3 e0cf701 7f902f3 e0cf701 7f902f3 e0cf701 7f902f3 e0cf701 7f902f3 e0cf701 7f902f3 e0cf701 7f902f3 e0cf701 7f902f3 e0cf701 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | import streamlit as st
import time
import random
import csv
import os
from faker import Faker
from playwright.sync_api import sync_playwright
st.set_page_config(page_title="Playwright HF Runner", layout="centered")
st.title("🤖 Playwright Automation (Hugging Face)")
# ---------------------------
# Safety checks
# ---------------------------
if not os.path.exists(os.path.expanduser("~/.cache/ms-playwright")):
st.error(
"Playwright browsers are not installed.\n\n"
"Make sure `playwright install chromium` is run during build."
)
st.stop()
# ---------------------------
# Data
# ---------------------------
NAMES = [
"Ahmad","Amin","Anas","Arif","Hadi","Hafiz","Ilyas","Irfan","Isa","Ismail",
"Jamal","Kareem","Mahmoud","Malik","Munir","Nadir","Nasser","Qasim","Rafi",
"Salim","Sami","Taha","Usama","Yahya","Zainab","Aisha","Amira","Asiya",
"Fatima","Hafsa","Iman","Iqra","Jamila","Maryam","Nour","Safiya","Salma"
]
def generate_data(count: int):
fake = Faker("en_US")
rows = []
for _ in range(count):
first = random.choice(NAMES)
last = random.choice(NAMES)
rows.append({
"name": f"{first} {last}",
"email": f"{first.lower()}.{last.lower()}{random.randint(1000,9999)}@gmail.com",
"password": fake.password(length=12)
})
with open("muslim_data.csv", "w", newline="", encoding="utf-8") as f:
writer = csv.DictWriter(f, fieldnames=["name", "email", "password"])
writer.writeheader()
writer.writerows(rows)
return rows
# ---------------------------
# UI
# ---------------------------
iterations = st.number_input(
"Iterations (keep LOW on HF)",
min_value=1,
max_value=5,
value=1
)
start = st.button("🚀 Start Automation")
log_area = st.empty()
def log(msg):
log_area.code(msg)
# ---------------------------
# Automation
# ---------------------------
if start:
st.warning("Running headless browser automation…")
data = generate_data(iterations)
URL = "https://vibe-to-hn-glow.lovable.app/#/product/5a3e92a6-72c0-45fd-9e4d-eb9ee9e4d3e7"
with sync_playwright() as p:
browser = p.chromium.launch(
headless=True,
args=[
"--no-sandbox",
"--disable-dev-shm-usage",
"--disable-gpu"
]
)
for i in range(iterations):
creds = data[i]
log(f"Iteration {i+1}\n{creds['email']}")
page = browser.new_page()
try:
page.goto(URL, timeout=60000)
page.wait_for_load_state("networkidle")
time.sleep(2)
upvote = page.locator(
'div.hn-item-row:has(a:has-text("Anqair")) button:has(span:has-text("▲"))'
).first
if upvote.is_visible():
upvote.click()
log("▲ Clicked")
create = page.locator('button.hn-link-orange:has-text("create one")').first
if create.is_visible():
create.click()
time.sleep(1)
page.locator('input[type="email"]').fill(creds["email"])
page.locator('input[type="password"]').fill(creds["password"])
page.locator('button:has-text("Create")').click()
log("Account created")
except Exception as e:
log(f"Error: {e}")
page.close()
time.sleep(1)
browser.close()
st.success("✅ Done")
|