-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautomation.py
More file actions
136 lines (109 loc) · 4.85 KB
/
Copy pathautomation.py
File metadata and controls
136 lines (109 loc) · 4.85 KB
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
126
127
128
129
130
131
132
133
134
135
136
import time
import re
from playwright.sync_api import Page, expect, Error, TimeoutError
def generate_temp_mail(page: Page) -> str:
"""
Retrieves a temporary email address from the temp mail provider.
Waits for the email generation button to appear before extracting the text.
"""
# Wait until the button containing the email address appears
email_button = page.locator("//button[p[contains(text(),'@')]]")
email_button.wait_for(timeout=10000)
# Extract the email address text from the <p> tag inside the button
email = email_button.locator("p").inner_text()
# Ensure the extracted email is valid and not empty
while not email.strip():
time.sleep(0.5)
email = email_button.locator("p").inner_text()
return email
def refresh_until_email_appears(page: Page, sender_email: str):
"""
Continuously checks for an email from the specified sender.
Clicks the 'Refresh' button if the email is not yet visible.
"""
while True:
try:
# Check if an email button containing the sender's address exists
email_btn = page.locator("button").filter(has_text=sender_email).first
if email_btn.is_visible():
print(f"Email from {sender_email} found!")
break # Stop clicking refresh once the email is found
except (Error, TimeoutError) as e:
pass
# If the email is not found, attempt to click the 'Refresh' button
try:
refresh_button = page.locator("button", has_text="Refresh").first
if refresh_button.is_visible():
refresh_button.click()
print("Clicked Refresh button")
else:
pass
except (Error, TimeoutError) as e:
print(f"Error clicking refresh: {e}")
time.sleep(1)
def click_email_when_appears(page: Page, sender_email: str):
"""
Waits for the email from the sender to appear and clicks it to open the message.
"""
while True:
try:
# Locate the button for the specific email and click it
email_button = page.locator("button").filter(has_text=sender_email).first
if email_button.is_visible():
email_button.click()
print(f"Clicked email from {sender_email}")
break # Exit loop after successful click
except (Error, TimeoutError) as e:
pass
# If the email isn't found yet, try refreshing the inbox
try:
refresh_button = page.locator("button", has_text="Refresh").first
if refresh_button.is_visible():
refresh_button.click()
print("Clicked Refresh button (in click_email loop)")
except (Error, TimeoutError) as e:
pass
time.sleep(2) # Wait briefly to allow the inbox to reload
def extract_url_from_message(page: Page, email_div_title: str) -> str:
"""
Extracts the IPTV playlist URL from the email content.
Searches for a div containing the specified title text.
"""
while True:
# Attempt to find the div that contains the playlist information.
# It may be plain text or nested within a bold <b> tag.
playlist_div = None
# Option 1: Search for div directly containing the text
loc1 = page.locator(f"//div[contains(text(),'{email_div_title}')]")
# Option 2: Search for div containing a bold tag with the text
loc2 = page.locator(f"//div[b[contains(text(),'{email_div_title}')]]")
if loc1.is_visible():
playlist_div = loc1
elif loc2.is_visible():
playlist_div = loc2
if playlist_div:
# Retrieve the full text content of the identified div
full_text = playlist_div.inner_text()
# Use regex to find the HTTP URL ending in .m3u
match = re.search(r"http://.*?/tv\.m3u", full_text)
if match:
playlist_url = match.group(0)
print("Playlist URL:", playlist_url)
return playlist_url
# If the URL hasn't been found, wait and try again
time.sleep(1)
def register_iptv_account(page: Page, email: str):
# Fill in the registration form with the temporary email
page.locator("input[name='email']").fill(email)
# Handle Google reCAPTCHA
# Locate the reCAPTCHA iframe
frame = page.frame_locator("iframe[src*='recaptcha']").first
# Click the "I'm not a robot" checkbox inside the iframe
checkbox = frame.locator("#recaptcha-anchor")
checkbox.click()
# Wait for captcha resolution
# Wait until the checkbox indicates it is checked (captcha solved)
expect(checkbox).to_have_class(re.compile(r"recaptcha-checkbox-checked"), timeout=600000)
# Submit the registration
# Click the registration button on the main page
page.locator("#regBtn").click()