Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
twitter_syncer
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Odysseus
twitter_syncer
Commits
9dd701e5
Commit
9dd701e5
authored
Oct 14, 2024
by
vicotor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
profile get followers
parent
17221a8d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
34 deletions
+51
-34
accounts.go
accounts.go
+48
-26
db.go
db.go
+3
-8
No files found.
accounts.go
View file @
9dd701e5
...
@@ -18,7 +18,7 @@ func generateTOTP(secret string) (string, error) {
...
@@ -18,7 +18,7 @@ func generateTOTP(secret string) (string, error) {
return
totp
.
GenerateCode
(
secret
,
time
.
Now
())
return
totp
.
GenerateCode
(
secret
,
time
.
Now
())
}
}
func
GetLoginAccount
()
([]
*
twitterscraper
.
Scrap
er
,
error
)
{
func
GetLoginAccount
()
([]
ScraperWithTim
er
,
error
)
{
accounts
,
err
:=
GetAvailableAccounts
()
accounts
,
err
:=
GetAvailableAccounts
()
...
@@ -28,7 +28,7 @@ func GetLoginAccount() ([]*twitterscraper.Scraper, error) {
...
@@ -28,7 +28,7 @@ func GetLoginAccount() ([]*twitterscraper.Scraper, error) {
fmt
.
Println
(
"len(accounts)"
,
len
(
accounts
))
fmt
.
Println
(
"len(accounts)"
,
len
(
accounts
))
res
:=
make
([]
*
twitterscraper
.
Scrap
er
,
0
,
len
(
accounts
))
res
:=
make
([]
ScraperWithTim
er
,
0
,
len
(
accounts
))
for
_
,
v
:=
range
accounts
{
for
_
,
v
:=
range
accounts
{
...
@@ -49,7 +49,10 @@ func GetLoginAccount() ([]*twitterscraper.Scraper, error) {
...
@@ -49,7 +49,10 @@ func GetLoginAccount() ([]*twitterscraper.Scraper, error) {
if
!
scraper
.
IsLoggedIn
()
{
if
!
scraper
.
IsLoggedIn
()
{
needLogin
=
true
needLogin
=
true
}
else
{
}
else
{
res
=
append
(
res
,
scraper
)
res
=
append
(
res
,
ScraperWithTimer
{
Scraper
:
scraper
,
AccountInfo
:
v
,
})
continue
continue
}
}
}
else
{
}
else
{
...
@@ -80,7 +83,10 @@ func GetLoginAccount() ([]*twitterscraper.Scraper, error) {
...
@@ -80,7 +83,10 @@ func GetLoginAccount() ([]*twitterscraper.Scraper, error) {
continue
continue
}
}
res
=
append
(
res
,
scraper
)
res
=
append
(
res
,
ScraperWithTimer
{
Scraper
:
scraper
,
AccountInfo
:
v
,
})
}
}
}
}
...
@@ -89,9 +95,8 @@ func GetLoginAccount() ([]*twitterscraper.Scraper, error) {
...
@@ -89,9 +95,8 @@ func GetLoginAccount() ([]*twitterscraper.Scraper, error) {
type
ScraperWithTimer
struct
{
type
ScraperWithTimer
struct
{
*
twitterscraper
.
Scraper
*
twitterscraper
.
Scraper
AccountInfo
Account
Timer
*
time
.
Timer
Timer
*
time
.
Timer
Email
string
UserName
string
}
}
var
accChan
chan
ScraperWithTimer
=
make
(
chan
ScraperWithTimer
,
20
)
var
accChan
chan
ScraperWithTimer
=
make
(
chan
ScraperWithTimer
,
20
)
...
@@ -166,15 +171,33 @@ func (f *FollowerRateLimit) Follower(userName string, cursor string) ([]*twitter
...
@@ -166,15 +171,33 @@ func (f *FollowerRateLimit) Follower(userName string, cursor string) ([]*twitter
if
err
:=
f
.
RateLimit
.
Wait
(
ctx
);
err
!=
nil
{
// This is a blocking call.
if
err
:=
f
.
RateLimit
.
Wait
(
ctx
);
err
!=
nil
{
// This is a blocking call.
return
nil
,
""
,
nil
,
err
return
nil
,
""
,
nil
,
err
}
}
var
(
history
=
make
(
map
[
string
]
bool
)
users
[]
*
twitterscraper
.
Profile
res
[]
*
twitter
.
UserObj
next
string
err
error
success
bool
=
false
try
=
0
)
for
!
success
&&
try
<
10
{
select
{
select
{
case
account
:=
<-
accChan
:
case
account
:=
<-
accChan
:
users
,
next
,
err
:=
account
.
FetchFollowers
(
userName
,
1000
,
cursor
)
accChan
<-
account
if
err
!=
nil
{
history
[
account
.
AccountInfo
.
Username
]
=
true
slog
.
Error
(
err
.
Error
())
if
_
,
exist
:=
history
[
account
.
AccountInfo
.
Username
];
exist
{
// loop all account, exit.
try
=
100
break
}
if
users
,
next
,
err
=
account
.
FetchFollowers
(
userName
,
1000
,
cursor
);
err
!=
nil
{
slog
.
Error
(
"FetchFollowers"
,
"failed"
,
err
.
Error
())
continue
}
}
res
:=
make
([]
*
twitter
.
UserObj
,
0
,
len
(
users
))
success
=
true
res
=
make
([]
*
twitter
.
UserObj
,
0
,
len
(
users
))
for
_
,
v
:=
range
users
{
for
_
,
v
:=
range
users
{
sDec
,
_
:=
base64
.
StdEncoding
.
DecodeString
(
v
.
UserID
)
sDec
,
_
:=
base64
.
StdEncoding
.
DecodeString
(
v
.
UserID
)
...
@@ -186,8 +209,7 @@ func (f *FollowerRateLimit) Follower(userName string, cursor string) ([]*twitter
...
@@ -186,8 +209,7 @@ func (f *FollowerRateLimit) Follower(userName string, cursor string) ([]*twitter
UserName
:
v
.
Username
,
UserName
:
v
.
Username
,
})
})
}
}
accChan
<-
account
return
res
,
next
,
nil
,
err
}
}
}
return
res
,
next
,
nil
,
err
}
}
db.go
View file @
9dd701e5
package
main
package
main
import
(
import
(
_
"code.wuban.net.cn/odysseus/twitter_syncer/docs"
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"log/slog"
"log/slog"
"time"
_
"code.wuban.net.cn/odysseus/twitter_syncer/docs"
// docs are generated by Swag CLI, you have to import them.
// docs are generated by Swag CLI, you have to import them.
// replace with your own docs folder, usually "github.com/username/reponame/docs"
// replace with your own docs folder, usually "github.com/username/reponame/docs"
//_ "github.com/gofiber/swagger/example/docs"
//_ "github.com/gofiber/swagger/example/docs"
...
@@ -42,12 +40,9 @@ func init() {
...
@@ -42,12 +40,9 @@ func init() {
slog
.
Error
(
err
.
Error
())
slog
.
Error
(
err
.
Error
())
}
}
for
k
,
v
:=
range
accounts
{
for
_
,
v
:=
range
accounts
{
//v.Timer = time.NewTimer(time.Duration(k) * time.Duration(5) * time.Minute)
//v.Timer = time.NewTimer(time.Duration(k) * time.Duration(5) * time.Minute)
accChan
<-
ScraperWithTimer
{
accChan
<-
v
Scraper
:
v
,
Timer
:
time
.
NewTimer
(
time
.
Duration
(
k
)
*
time
.
Duration
(
5
)
*
time
.
Minute
),
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment