新增获取账号地址的方法
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
func ExportTwitterAccounts() ([]string, error) {
|
||||
accountService := InitTwitterAccountService()
|
||||
accounts := accountService.GetAll(&models.TwitterAccount{
|
||||
Type: "get",
|
||||
Type: "get_address",
|
||||
})
|
||||
|
||||
// 分类
|
||||
@@ -37,7 +37,7 @@ func ExportTwitterAccounts() ([]string, error) {
|
||||
continue
|
||||
}
|
||||
file := excelize.NewFile()
|
||||
titles := []string{"编号", "用户id", "用户名", "邮箱", "密码", "邮箱密码", "生日", "Token", "二步验证码", "Cookies", "类型", "状态", "登录状态", "代理", "浏览器ID", "浏览器地址", "注册时间", "注册地区", "注册IP", "更新时间", "创建时间"}
|
||||
titles := []string{"编号", "用户id", "用户名", "邮箱", "密码", "邮箱密码", "生日", "Token", "二步验证码", "Cookies", "类型", "状态", "登录状态", "代理", "浏览器ID", "浏览器地址", "注册时间", "注册地区", "注册IP", "地址", "更新时间", "创建时间"}
|
||||
for i, t := range titles {
|
||||
cell, _ := excelize.CoordinatesToCellName(i+1, 1)
|
||||
file.SetCellValue("Sheet1", cell, t)
|
||||
@@ -63,6 +63,7 @@ func ExportTwitterAccounts() ([]string, error) {
|
||||
acc.RegisterDate,
|
||||
acc.RegisterAddress,
|
||||
acc.RegisterIp,
|
||||
acc.Address,
|
||||
acc.UpdateTime,
|
||||
acc.CreateTime,
|
||||
}
|
||||
|
||||
@@ -126,3 +126,18 @@ func (u *TwitterAccountService) GetAvailableImportAccount(params *models.Twitter
|
||||
|
||||
return users
|
||||
}
|
||||
|
||||
// 随机获取一个可用账号
|
||||
func (u *TwitterAccountService) GetRandomAccount(params *models.TwitterAccount) *models.TwitterAccount {
|
||||
var account models.TwitterAccount
|
||||
res := u.db.Model(&models.TwitterAccount{}).Where(`type = ? AND login_status IS NULL AND (status != ? OR status IS NULL)`, params.Type, params.Status)
|
||||
// if params.Username != "" {
|
||||
// res.Where("username LIKE ?", "%"+params.Username+"%")
|
||||
// }
|
||||
res.Order("RAND()").Limit(1).Find(&account)
|
||||
if account.ID == 0 {
|
||||
return nil
|
||||
}
|
||||
u.db.Model(&models.TwitterAccount{}).Where("id = ?", account.ID).Updates(map[string]interface{}{"login_status": "已选择", "update_time": time.Now().Unix()})
|
||||
return &account
|
||||
}
|
||||
|
||||
@@ -109,11 +109,52 @@ func (*TwitterService) Login(id int) *libs.ErrorInfo {
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
getAccountInfo(page, int64(id))
|
||||
getRegisterInfo(page, int64(id), user.Password)
|
||||
// getAccountInfo(page, int64(id))
|
||||
// getRegisterInfo(page, int64(id), user.Password)
|
||||
return libs.ErrorCode["LoginSuccessful"]
|
||||
}
|
||||
|
||||
func (*TwitterService) GetAccountAddress(id int) *libs.ErrorInfo {
|
||||
UserService := InitTwitterAccountService()
|
||||
user := UserService.GetInfo(int64(id))
|
||||
obj := Browser.GetBrowser(id, &libs.Fingerprint{
|
||||
Proxy: user.Proxy,
|
||||
})
|
||||
// browser := obj.Browser
|
||||
page := obj.Page
|
||||
// 循环获取可用账号 到获取不到为止
|
||||
is := true
|
||||
for is {
|
||||
account := UserService.GetRandomAccount(&models.TwitterAccount{Type: "get_address", Status: "成功"})
|
||||
if account == nil {
|
||||
is = false
|
||||
}
|
||||
rod.Try(func() {
|
||||
// 进入账号信息页面
|
||||
page.MustNavigate("https://x.com/" + account.Name + "/about").MustWaitLoad()
|
||||
page.MustWaitNavigation()
|
||||
page.MustWaitLoad() // DOM 加载完成
|
||||
page.MustWaitIdle() // 基本静止(减少早期误判)
|
||||
page.MustActivate() // 前置
|
||||
// 获取地理位置
|
||||
locationElement, err := page.Timeout(10 * time.Second).Element(`#react-root > div > div > div.css-175oi2r.r-1f2l425.r-13qz1uu.r-417010.r-18u37iz > main > div > div > div > div.css-175oi2r.r-14lw9ot.r-jxzhtn.r-1ua6aaf.r-th6na.r-1phboty.r-16y2uox.r-184en5c.r-1abdc3e.r-1lg4w6u.r-f8sm7e.r-13qz1uu.r-1ye8kvj > div > div.css-175oi2r.r-16pcm1t > div.css-175oi2r.r-1wtj0ep.r-16x9es5.r-1mmae3n.r-1loqt21.r-o7ynqc.r-6416eg.r-1ny4l3l > div > div.css-175oi2r.r-16y2uox.r-1wbh5a2 > div:nth-child(2)`)
|
||||
if err == nil {
|
||||
location, _ := locationElement.Text()
|
||||
UserService.Update(account.ID, &models.TwitterAccount{
|
||||
Address: location,
|
||||
Status: "成功",
|
||||
})
|
||||
} else {
|
||||
UserService.Update(account.ID, &models.TwitterAccount{
|
||||
Status: "失败",
|
||||
})
|
||||
}
|
||||
time.Sleep(3 * time.Second)
|
||||
})
|
||||
}
|
||||
return libs.ErrorCode["GetAddressSuccessful"]
|
||||
}
|
||||
|
||||
// 获取账号信息
|
||||
func getAccountInfo(page *rod.Page, id int64) {
|
||||
profileButton := page.Timeout(10 * time.Second).MustElement(`a[data-testid="AppTabBar_Profile_Link"]`)
|
||||
|
||||
Reference in New Issue
Block a user