-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.py
More file actions
76 lines (66 loc) · 2.5 KB
/
functions.py
File metadata and controls
76 lines (66 loc) · 2.5 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
import sys
import time
import os
from termcolor import colored
import undetected_chromedriver as uc
from py_imessage import imessage
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
def clean_text(tweet: str) -> tuple[str, bool]:
try:
tweet = tweet.lower()
tweet = tweet.split("text", 1)[1]
tweet = tweet.split(" ")[1]
tweet = tweet.strip()
tweet = tweet.upper()
except(IndexError):
return "No code found", False
return tweet, True
def get_current_time() -> str:
t = time.localtime()
current_time = time.strftime("%H:%M:%S", t)
return current_time
def get_latest_tweet(driver: uc.Chrome, TWEET_XPATH: str) -> str:
WebDriverWait(driver, 25).until(EC.visibility_of_element_located((By.XPATH, TWEET_XPATH)))
tweet_element = driver.find_element(By.XPATH, TWEET_XPATH)
return tweet_element.text
def loop_twitter_page(driver: uc.Chrome, TWEET_XPATH: str, last_tweet: str) -> str:
i = 1
while True:
driver.refresh()
WebDriverWait(driver, 25).until(EC.visibility_of_element_located((By.XPATH, TWEET_XPATH)))
tweet_element = driver.find_element(By.XPATH, TWEET_XPATH)
print(f"DRIVER IS RUNNING, TIMES REFRESHED: {i}", end='\r')
sys.stdout.flush()
i += 1
if tweet_element.text != last_tweet:
print("")
last_tweet = tweet_element.text
resp, code_found = clean_text(tweet_element.text)
if code_found:
print(f"Code found at {get_current_time()} ({resp})")
return resp
else:
print(resp)
def countdown(i = 25):
for _ in range(i):
print(f"Restarting in {i} seconds, CTRL + C to cancel ", end='\r')
sys.stdout.flush()
i -= 1
time.sleep(1)
os.system("clear")
def send_text(code: str) -> str:
imessage.send("888222", code)
return f"Text sent at {get_current_time()}! ({code})\nPlease check your phone"
def title():
title_ascii = '''
____ _ _ _ _ _____ ____
/ ___| |__ (_)_ __ ___ | |_| | ___ | ___| _ \
| | | '_ \| | '_ \ / _ \| __| |/ _ \ | |_ | |_) |
| |___| | | | | |_) | (_) | |_| | __/ | _| | __/
\____|_| |_|_| .__/ \___/ \__|_|\___| |_| |_|
|_|
https://github.com/EvilWumpus
'''
print(colored(title_ascii, "green"))