Skip to content

Commit

Permalink
Merge branch 'chengazhen:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
wqjuser authored Jan 17, 2025
2 parents 7178856 + 3d8cfc4 commit b0a2fbb
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 68 deletions.
4 changes: 2 additions & 2 deletions README.EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ Automated account registration and token refreshing to free your hands.

## Configuration Instructions
- Use a Cloudflare domain email. Search for instructions if needed.
- **(Very Important)** Use temp-mail.plus email. Search for instructions if needed.
- Forward Cloudflare emails to temp-mail.plus.
- **(Very Important)** Use tempmail.plus email. Search for instructions if needed.
- Forward Cloudflare emails to tempmail.plus.
- Download the `.env.example` file to the program's root directory and rename it to `.env`.

### Example `.env` file:
Expand Down
4 changes: 2 additions & 2 deletions README.VI.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ Tự động đăng ký tài khoản, tự động làm mới token, giải phó

## Hướng Dẫn Cấu Hình
- Cần sử dụng email theo tên miền Cloudflare. Hãy tìm hiểu cách sử dụng.
- **(Rất quan trọng)** Cần sử dụng email tạm thời từ temp-mail.plus. Hãy tìm hiểu cách sử dụng.
- Chuyển tiếp email từ tên miền Cloudflare sang temp-mail.plus.
- **(Rất quan trọng)** Cần sử dụng email tạm thời từ tempmail.plus. Hãy tìm hiểu cách sử dụng.
- Chuyển tiếp email từ tên miền Cloudflare sang tempmail.plus.
- Tải tệp `.env.example` về thư mục gốc của chương trình và đổi tên thành `.env`.

### Cấu hình tệp `.env`:
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ README also avaiable in: [English](./README.EN.md), [Tiếng Việt](./README.VI

## 最近有人把软件拿到咸鱼卖的,这种事情尽量少干吧。不至于什么钱都挣。


## 许可证声明
本项目采用 [CC BY-NC-ND 4.0](https://creativecommons.org/licenses/by-nc-nd/4.0/) 许可证。
这意味着您可以:
Expand All @@ -18,6 +19,8 @@ README also avaiable in: [English](./README.EN.md), [Tiếng Việt](./README.VI
## 下载地址
https://github.com/chengazhen/cursor-auto-free/releases



## 重要提示
**1.确保你有一个chrome浏览器;如果你没有;[下载地址](https://www.google.com/intl/en_pk/chrome/)**

Expand Down Expand Up @@ -89,6 +92,10 @@ chmod +x ./CursorPro
2. 使用过程中:
- 等待程序自动完成所有操作
- 看到"脚本执行完毕"提示后再关闭程序

## 赞助更有动力更新

![image](./screen/afdian-[未认证]阿臻.jpg)

## 常见问题解决

Expand Down
7 changes: 4 additions & 3 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ def check_config(self):
if not self.check_is_valid(self.domain):
raise ValueError("域名未配置,请在 .env 文件中设置 DOMAIN")

logging.info(f"\033[32m临时邮箱: {self.temp_mail}\033[0m")
logging.info(f"\033[32m域名: {self.domain}\033[0m")

def check_is_valid(self, str):
return len(str.strip()) > 0

def print_config(self):
logging.info(f"\033[32m临时邮箱: {self.temp_mail}\033[0m")
logging.info(f"\033[32m域名: {self.domain}\033[0m")


# 使用示例
if __name__ == "__main__":
Expand Down
10 changes: 7 additions & 3 deletions cursor_pro_keep_alive.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,19 @@ def __init__(
)
),
):
self.domain = Config().get_domain()
configInstance = Config()
configInstance.print_config()
self.domain = configInstance.get_domain()
self.default_password = password
self.default_first_name = self.generate_random_name()
self.default_last_name = self.generate_random_name()

def generate_random_name(self, length=6):
"""生成随机用户名"""
first_letter = random.choice("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
rest_letters = ''.join(random.choices("abcdefghijklmnopqrstuvwxyz", k=length-1))
rest_letters = "".join(
random.choices("abcdefghijklmnopqrstuvwxyz", k=length - 1)
)
return first_letter + rest_letters

def generate_email(self, length=8):
Expand Down Expand Up @@ -257,7 +261,7 @@ def get_account_info(self):
browser = browser_manager.init_browser()

logging.info("正在初始化邮箱验证模块...")
email_handler = EmailVerificationHandler(browser)
email_handler = EmailVerificationHandler()

logging.info("\n=== 配置信息 ===")
login_url = "https://authenticator.cursor.sh"
Expand Down
124 changes: 66 additions & 58 deletions get_email_code.py
Original file line number Diff line number Diff line change
@@ -1,81 +1,89 @@
from DrissionPage.common import Keys
import time
import re
from config import Config
import requests


class EmailVerificationHandler:
def __init__(self, browser, mail_url="https://tempmail.plus"):
self.browser = browser
self.mail_url = mail_url
def __init__(self):
self.username = Config().get_temp_mail()
self.session = requests.Session()
self.emailExtension = "@mailto.plus"

def get_verification_code(self):
code = None

try:
print("正在处理...")
# 打开新标签页访问临时邮箱
tab_mail = self.browser.new_tab(self.mail_url)
self.browser.activate_tab(tab_mail)

# 输入用户名
self._input_username(tab_mail)

# 等待并获取最新邮件
code = self._get_latest_mail_code(tab_mail)
code, first_id = self._get_latest_mail_code()

# 清理邮件
self._cleanup_mail(tab_mail)

# 关闭标签页
tab_mail.close()
self._cleanup_mail(first_id)

except Exception as e:
print(f"获取验证码失败: {str(e)}")

return code

def _input_username(self, tab):
while True:
if tab.ele("@id=pre_button"):
tab.actions.click("@id=pre_button")
time.sleep(0.5)
tab.run_js('document.getElementById("pre_button").value = ""')
time.sleep(0.5)
tab.actions.input(self.username).key_down(Keys.ENTER).key_up(Keys.ENTER)
break
time.sleep(1)

def _get_latest_mail_code(self, tab):
code = None
while True:
new_mail = tab.ele("@class=mail")
if new_mail:
if new_mail.text:
tab.actions.click("@class=mail")
break
else:
break
time.sleep(1)

if tab.ele("@class=overflow-auto mb-20"):
email_content = tab.ele("@class=overflow-auto mb-20").text
verification_code = re.search(
r"verification code is (\d{6})", email_content
)
if verification_code:
code = verification_code.group(1)
print("马上就要成功了")
else:
print("执行失败")

return code

def _cleanup_mail(self, tab):
if tab.ele("@id=delete_mail"):
tab.actions.click("@id=delete_mail")
time.sleep(1)

if tab.ele("@id=confirm_mail"):
tab.actions.click("@id=confirm_mail")
# 手动输入验证码
def _get_latest_mail_code(self):
# 获取邮件列表
mail_list_url = f"https://tempmail.plus/api/mails?email={self.username}{self.emailExtension}&limit=20&epin="
mail_list_response = self.session.get(mail_list_url)
mail_list_data = mail_list_response.json()
time.sleep(0.5)
if not mail_list_data.get("result"):
return None, None

# 获取最新邮件的ID
first_id = mail_list_data.get("first_id")
if not first_id:
return None, None

# 获取具体邮件内容
mail_detail_url = f"https://tempmail.plus/api/mails/{first_id}?email={self.username}{self.emailExtension}&epin="
mail_detail_response = self.session.get(mail_detail_url)
mail_detail_data = mail_detail_response.json()
time.sleep(0.5)
if not mail_detail_data.get("result"):
return None, None

# 从邮件文本中提取6位数字验证码
mail_text = mail_detail_data.get("text", "")
code_match = re.search(r"\b\d{6}\b", mail_text)

if code_match:
return code_match.group(), first_id
return None, None

def _cleanup_mail(self, first_id):
# 构造删除请求的URL和数据
delete_url = "https://tempmail.plus/api/mails/"
payload = {
"email": f"{self.username}{self.emailExtension}",
"first_id": first_id,
"epin": "",
}

# 最多尝试5次
for _ in range(5):
response = self.session.delete(delete_url, data=payload)
try:
result = response.json().get("result")
if result is True:
return True
except:
pass

# 如果失败,等待0.5秒后重试
time.sleep(0.5)

return False


if __name__ == "__main__":
email_handler = EmailVerificationHandler()
code = email_handler.get_verification_code()
print(code)
Binary file added screen/afdian-[未认证]阿臻.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b0a2fbb

Please sign in to comment.