Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import nest_asyncio
|
| 3 |
+
import asyncio
|
| 4 |
+
import re
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
from protonmail import ProtonMail
|
| 8 |
+
|
| 9 |
+
nest_asyncio.apply()
|
| 10 |
+
|
| 11 |
+
username = "laygyi5566@proton.me"
|
| 12 |
+
password = "htz175039"
|
| 13 |
+
|
| 14 |
+
proton = ProtonMail()
|
| 15 |
+
|
| 16 |
+
# Only login and save session once
|
| 17 |
+
if not os.path.exists("session.pickle"):
|
| 18 |
+
proton.login(username, password)
|
| 19 |
+
proton.save_session("session.pickle")
|
| 20 |
+
|
| 21 |
+
# Load session
|
| 22 |
+
proton.load_session("session.pickle", auto_save=True)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
async def fetch_verification_code():
|
| 26 |
+
messages = proton.get_messages()
|
| 27 |
+
if not messages:
|
| 28 |
+
return "❌ No messages found.", ""
|
| 29 |
+
|
| 30 |
+
message = proton.read_message(messages[0])
|
| 31 |
+
sender = message.sender.address
|
| 32 |
+
subject = message.subject
|
| 33 |
+
body = message.body
|
| 34 |
+
|
| 35 |
+
code_match = re.search(r"\b\d{6}\b", body)
|
| 36 |
+
if code_match:
|
| 37 |
+
verification_code = code_match.group()
|
| 38 |
+
result = f"✅ Verification code: {verification_code}"
|
| 39 |
+
else:
|
| 40 |
+
result = "❌ No verification code found."
|
| 41 |
+
|
| 42 |
+
# Save HTML (optional)
|
| 43 |
+
with open("message.html", "w", encoding="utf-8") as f:
|
| 44 |
+
f.write(body)
|
| 45 |
+
|
| 46 |
+
log = f"From: {sender}\nSubject: {subject}\n\n{body}"
|
| 47 |
+
return result, log
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def get_code_button_click():
|
| 51 |
+
loop = asyncio.new_event_loop()
|
| 52 |
+
asyncio.set_event_loop(loop)
|
| 53 |
+
result, log = loop.run_until_complete(fetch_verification_code())
|
| 54 |
+
return result, log
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
# Gradio UI
|
| 58 |
+
with gr.Blocks() as demo:
|
| 59 |
+
gr.Markdown("## ProtonMail Verification Code Fetcher")
|
| 60 |
+
|
| 61 |
+
get_code_button = gr.Button("Get Verification Code")
|
| 62 |
+
code_output = gr.Textbox(label="Verification Code", interactive=False)
|
| 63 |
+
log_output = gr.Textbox(label="Message Log", lines=15, interactive=False)
|
| 64 |
+
|
| 65 |
+
get_code_button.click(fn=get_code_button_click, outputs=[code_output, log_output])
|
| 66 |
+
|
| 67 |
+
demo.launch()
|