first
This commit is contained in:
commit
37ed3ab73f
|
@ -0,0 +1,4 @@
|
|||
.idea/
|
||||
venv/
|
||||
.env
|
||||
__pycache__/
|
|
@ -0,0 +1,116 @@
|
|||
import imaplib
|
||||
import os
|
||||
|
||||
import pyzmail
|
||||
import time
|
||||
from dotenv import load_dotenv
|
||||
from bs4 import BeautifulSoup
|
||||
import requests
|
||||
|
||||
load_dotenv()
|
||||
|
||||
global xsrf_token
|
||||
global csrf_token
|
||||
global session
|
||||
|
||||
mail = imaplib.IMAP4_SSL(os.getenv('HOST'))
|
||||
mail.login(os.getenv('USERNAME'), os.getenv('PASSWORD'))
|
||||
mail.select('inbox')
|
||||
|
||||
|
||||
def roll_token():
|
||||
global xsrf_token
|
||||
global csrf_token
|
||||
global session
|
||||
|
||||
cookies = {
|
||||
os.getenv('COOKIE_NAME'): os.getenv('COOKIE_VALUE'),
|
||||
'sketchers_united_session': os.getenv('STARTUP_SESSION_VALUE')
|
||||
}
|
||||
|
||||
headers = {
|
||||
'User-Agent': 'automod',
|
||||
}
|
||||
|
||||
get_page_correctly = False
|
||||
response = None
|
||||
|
||||
while not get_page_correctly:
|
||||
response = requests.get(f'https://sketchersunited.org', cookies=cookies, headers=headers)
|
||||
|
||||
if response.status_code == 200:
|
||||
session = response.cookies["sketchers_united_session"]
|
||||
xsrf_token = response.cookies["XSRF-TOKEN"]
|
||||
|
||||
get_page_correctly = True
|
||||
else:
|
||||
print("An error occurred trying to get the page when rolling tokens, retrying")
|
||||
|
||||
soup = BeautifulSoup(response.text, 'html.parser')
|
||||
csrf_token = soup.find('meta', {'name': 'csrf-token'}).get('content')
|
||||
|
||||
|
||||
def send_message(text):
|
||||
roll_token()
|
||||
|
||||
cookies = {
|
||||
os.getenv('COOKIE_NAME'): os.getenv('COOKIE_VALUE'),
|
||||
'sketchers_united_session': os.getenv('STARTUP_SESSION_VALUE'),
|
||||
'XSRF-TOKEN': xsrf_token
|
||||
}
|
||||
|
||||
headers = {
|
||||
'User-Agent': 'automod',
|
||||
'Accept': 'application/json, */*',
|
||||
'X-CSRF-TOKEN': csrf_token,
|
||||
'X-XSRF-TOKEN': xsrf_token,
|
||||
'Content-Type': 'multipart/form-data; boundary=---------------------------9051447283201882072943098316'
|
||||
}
|
||||
|
||||
data = (f'-----------------------------9051447283201882072943098316'
|
||||
f'\r\nContent-Disposition: form-data; '
|
||||
f'name="text"\r\n\r\n{text}'
|
||||
f'\r\n-----------------------------9051447283201882072943098316--\r\n').encode()
|
||||
|
||||
response = requests.post('https://sketchersunited.org/chats/395457/messages', cookies=cookies, data=data,
|
||||
headers=headers)
|
||||
|
||||
if response.status_code != 200 and response.status_code != 201:
|
||||
print(f"There was an issue with sending a message: {response.status_code}")
|
||||
print(response.request.headers)
|
||||
|
||||
|
||||
def get_inbox():
|
||||
result, data = mail.search(None, 'UNSEEN')
|
||||
if result == "OK":
|
||||
for num in data[0].split():
|
||||
result, data = mail.fetch(num, '(RFC822)')
|
||||
if result == "OK":
|
||||
raw_email = data[0][1]
|
||||
try:
|
||||
email_message = pyzmail.PyzMessage.factory(raw_email)
|
||||
|
||||
final_message = ""
|
||||
|
||||
subject = email_message.get_subject()
|
||||
final_message += f"📧 *{subject}*\n"
|
||||
|
||||
if email_message.text_part:
|
||||
body = email_message.text_part.get_payload().decode(email_message.text_part.charset)
|
||||
final_message += str(body)
|
||||
if email_message.html_part:
|
||||
body = email_message.html_part.get_payload().decode(email_message.html_part.charset)
|
||||
final_message += str(body)
|
||||
send_message(final_message)
|
||||
except:
|
||||
print("WTF!")
|
||||
print(raw_email)
|
||||
|
||||
|
||||
try:
|
||||
while True:
|
||||
get_inbox()
|
||||
print("Checking")
|
||||
time.sleep(1)
|
||||
finally:
|
||||
mail.logout()
|
|
@ -0,0 +1,4 @@
|
|||
pyzmail36
|
||||
requests
|
||||
python-dotenv
|
||||
beautifulsoup4
|
Loading…
Reference in New Issue