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
3af78dfd
Commit
3af78dfd
authored
Aug 04, 2024
by
Ubuntu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
retweet task ok
parent
1219bc0b
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
310 additions
and
103 deletions
+310
-103
cookies.json
cookies.json
+56
-56
stream.go
stream.go
+55
-23
stream_idx.go
stream_idx.go
+52
-4
task.go
task.go
+10
-13
type.go
type.go
+137
-7
No files found.
cookies.json
View file @
3af78dfd
[
[
{
{
"domain"
:
".twitter.com"
,
"domain"
:
".twitter.com"
,
"expirationDate"
:
1756348784.685643
,
"hostOnly"
:
false
,
"hostOnly"
:
false
,
"httpOnly"
:
tru
e
,
"httpOnly"
:
fals
e
,
"name"
:
"_
twitter_sess
"
,
"name"
:
"_
ga
"
,
"path"
:
"/"
,
"path"
:
"/"
,
"sameSite"
:
"unspecified"
,
"sameSite"
:
"unspecified"
,
"secure"
:
tru
e
,
"secure"
:
fals
e
,
"session"
:
tru
e
,
"session"
:
fals
e
,
"storeId"
:
"0"
,
"storeId"
:
"0"
,
"value"
:
"
BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%250ASGFzaHsABjoKQHVzZWR7AA%253D%253D--1164b91ac812d853b877e93ddb612b7471bebc74
"
,
"value"
:
"
GA1.2.1387953141.1721788785
"
,
"id"
:
1
"id"
:
1
},
},
{
{
"domain"
:
".twitter.com"
,
"domain"
:
".twitter.com"
,
"expirationDate"
:
1722772659.123745
,
"hostOnly"
:
false
,
"hostOnly"
:
false
,
"httpOnly"
:
true
,
"httpOnly"
:
true
,
"name"
:
"
att
"
,
"name"
:
"
_twitter_sess
"
,
"path"
:
"/"
,
"path"
:
"/"
,
"sameSite"
:
"
no_restriction
"
,
"sameSite"
:
"
unspecified
"
,
"secure"
:
true
,
"secure"
:
true
,
"session"
:
fals
e
,
"session"
:
tru
e
,
"storeId"
:
"0"
,
"storeId"
:
"0"
,
"value"
:
"
1-t27ASoVioPwK483s1zzCcXADK63c5SMNU0SbLt3i
"
,
"value"
:
"
BAh7CSIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%250ASGFzaHsABjoKQHVzZWR7ADoPY3JlYXRlZF9hdGwrCFW%252FuN6QAToMY3NyZl9p%250AZCIlMmY4NmMwNTcxYzhjY2RkYmE2MTQwNWI0NDBjMDJjZWY6B2lkIiUyMzZh%250AODljY2Q3MTY5MDE2NDQ0ZmUxNmFiNzgxOTljNg%253D%253D--14854efc1913bc8618de3f72817a90f681021de9
"
,
"id"
:
2
"id"
:
2
},
},
{
{
"domain"
:
".twitter.com"
,
"domain"
:
".twitter.com"
,
"expirationDate"
:
1756
900658.284772
,
"expirationDate"
:
1756
283662.960466
,
"hostOnly"
:
false
,
"hostOnly"
:
false
,
"httpOnly"
:
true
,
"httpOnly"
:
true
,
"name"
:
"auth_token"
,
"name"
:
"auth_token"
,
...
@@ -37,12 +37,12 @@
...
@@ -37,12 +37,12 @@
"secure"
:
true
,
"secure"
:
true
,
"session"
:
false
,
"session"
:
false
,
"storeId"
:
"0"
,
"storeId"
:
"0"
,
"value"
:
"
b3cb77558ba11670d592387937b2cd86355f8925
"
,
"value"
:
"
6694c415423126c4099fc819b7d4142b578ebf23
"
,
"id"
:
3
"id"
:
3
},
},
{
{
"domain"
:
".twitter.com"
,
"domain"
:
".twitter.com"
,
"expirationDate"
:
1756
900658.690693
,
"expirationDate"
:
1756
283663.360468
,
"hostOnly"
:
false
,
"hostOnly"
:
false
,
"httpOnly"
:
false
,
"httpOnly"
:
false
,
"name"
:
"ct0"
,
"name"
:
"ct0"
,
...
@@ -51,54 +51,40 @@
...
@@ -51,54 +51,40 @@
"secure"
:
true
,
"secure"
:
true
,
"session"
:
false
,
"session"
:
false
,
"storeId"
:
"0"
,
"storeId"
:
"0"
,
"value"
:
"
e7d3edebd701cd68c1d9ca4ac755e71b896d1a3e03c4b7f77610f687fd6365967f61aaf5b6ab9bfb21fe9d7a38e4b92bf63c9193c2d7a0be42ae2e9f2252b9e789b2bc0917f70648f8c8be44645ccbea
"
,
"value"
:
"
fef7fe7d5d33870bef38f705111f2d16b3ab6236e89312d7339eb792b2f3c7faf25345307fc1509264eb277368f5bdaa9392b85de1941f2423d0180debd9efc8c312b6f8a4b7ddcd348c677fb3cc3d56
"
,
"id"
:
4
"id"
:
4
},
},
{
{
"domain"
:
".twitter.com"
,
"domain"
:
".twitter.com"
,
"expirationDate"
:
1756
895711.574034
,
"expirationDate"
:
1756
348723.939432
,
"hostOnly"
:
false
,
"hostOnly"
:
false
,
"httpOnly"
:
false
,
"httpOnly"
:
false
,
"name"
:
"d
nt
"
,
"name"
:
"d
es_opt_in
"
,
"path"
:
"/"
,
"path"
:
"/"
,
"sameSite"
:
"
no_restriction
"
,
"sameSite"
:
"
unspecified
"
,
"secure"
:
tru
e
,
"secure"
:
fals
e
,
"session"
:
false
,
"session"
:
false
,
"storeId"
:
"0"
,
"storeId"
:
"0"
,
"value"
:
"
1
"
,
"value"
:
"
N
"
,
"id"
:
5
"id"
:
5
},
},
{
{
"domain"
:
".twitter.com"
,
"domain"
:
".twitter.com"
,
"expirationDate"
:
17
23289601.759261
,
"expirationDate"
:
17
56451096.332794
,
"hostOnly"
:
false
,
"hostOnly"
:
false
,
"httpOnly"
:
false
,
"httpOnly"
:
false
,
"name"
:
"
external_referer
"
,
"name"
:
"
dnt
"
,
"path"
:
"/"
,
"path"
:
"/"
,
"sameSite"
:
"
unspecified
"
,
"sameSite"
:
"
no_restriction
"
,
"secure"
:
true
,
"secure"
:
true
,
"session"
:
false
,
"session"
:
false
,
"storeId"
:
"0"
,
"storeId"
:
"0"
,
"value"
:
"
padhuUp37zjgzgv1mFWxJ5Xq0CLV%2BbpWuS41v6lN3QU%3D|0|8e8t2xd8A2w%3D
"
,
"value"
:
"
1
"
,
"id"
:
6
"id"
:
6
},
},
{
{
"domain"
:
".twitter.com"
,
"domain"
:
".twitter.com"
,
"expirationDate"
:
1722688497.654729
,
"expirationDate"
:
1751425532.227206
,
"hostOnly"
:
false
,
"httpOnly"
:
false
,
"name"
:
"gt"
,
"path"
:
"/"
,
"sameSite"
:
"unspecified"
,
"secure"
:
true
,
"session"
:
false
,
"storeId"
:
"0"
,
"value"
:
"1819675816772730888"
,
"id"
:
7
},
{
"domain"
:
".twitter.com"
,
"expirationDate"
:
1756895712.329647
,
"hostOnly"
:
false
,
"hostOnly"
:
false
,
"httpOnly"
:
false
,
"httpOnly"
:
false
,
"name"
:
"guest_id"
,
"name"
:
"guest_id"
,
...
@@ -107,12 +93,12 @@
...
@@ -107,12 +93,12 @@
"secure"
:
true
,
"secure"
:
true
,
"session"
:
false
,
"session"
:
false
,
"storeId"
:
"0"
,
"storeId"
:
"0"
,
"value"
:
"v1%3A17
2268131226928865
"
,
"value"
:
"v1%3A17
0860225263973367
"
,
"id"
:
8
"id"
:
7
},
},
{
{
"domain"
:
".twitter.com"
,
"domain"
:
".twitter.com"
,
"expirationDate"
:
1757
239567.820
636
,
"expirationDate"
:
1757
316314.85
636
,
"hostOnly"
:
false
,
"hostOnly"
:
false
,
"httpOnly"
:
false
,
"httpOnly"
:
false
,
"name"
:
"guest_id_ads"
,
"name"
:
"guest_id_ads"
,
...
@@ -121,12 +107,12 @@
...
@@ -121,12 +107,12 @@
"secure"
:
true
,
"secure"
:
true
,
"session"
:
false
,
"session"
:
false
,
"storeId"
:
"0"
,
"storeId"
:
"0"
,
"value"
:
"v1%3A17
226794954899388
7"
,
"value"
:
"v1%3A17
086022526397336
7"
,
"id"
:
9
"id"
:
8
},
},
{
{
"domain"
:
".twitter.com"
,
"domain"
:
".twitter.com"
,
"expirationDate"
:
1757
239567.820538
,
"expirationDate"
:
1757
316314.856412
,
"hostOnly"
:
false
,
"hostOnly"
:
false
,
"httpOnly"
:
false
,
"httpOnly"
:
false
,
"name"
:
"guest_id_marketing"
,
"name"
:
"guest_id_marketing"
,
...
@@ -135,12 +121,12 @@
...
@@ -135,12 +121,12 @@
"secure"
:
true
,
"secure"
:
true
,
"session"
:
false
,
"session"
:
false
,
"storeId"
:
"0"
,
"storeId"
:
"0"
,
"value"
:
"v1%3A17
226794954899388
7"
,
"value"
:
"v1%3A17
086022526397336
7"
,
"id"
:
10
"id"
:
9
},
},
{
{
"domain"
:
".twitter.com"
,
"domain"
:
".twitter.com"
,
"expirationDate"
:
1756
900658.284168
,
"expirationDate"
:
1756
283662.960332
,
"hostOnly"
:
false
,
"hostOnly"
:
false
,
"httpOnly"
:
true
,
"httpOnly"
:
true
,
"name"
:
"kdt"
,
"name"
:
"kdt"
,
...
@@ -149,12 +135,12 @@
...
@@ -149,12 +135,12 @@
"secure"
:
true
,
"secure"
:
true
,
"session"
:
false
,
"session"
:
false
,
"storeId"
:
"0"
,
"storeId"
:
"0"
,
"value"
:
"
n4OBqkWAyTvlv8c0AVr7eJ07cldRIlGw9rVRpcHI
"
,
"value"
:
"
LvWUyXTiPsV6xBShzLMHFKwP1lA2QtXqGG3BbgFj
"
,
"id"
:
1
1
"id"
:
1
0
},
},
{
{
"domain"
:
".twitter.com"
,
"domain"
:
".twitter.com"
,
"expirationDate"
:
17542
22260.197705
,
"expirationDate"
:
17542
92309.732566
,
"hostOnly"
:
false
,
"hostOnly"
:
false
,
"httpOnly"
:
false
,
"httpOnly"
:
false
,
"name"
:
"night_mode"
,
"name"
:
"night_mode"
,
...
@@ -164,11 +150,11 @@
...
@@ -164,11 +150,11 @@
"session"
:
false
,
"session"
:
false
,
"storeId"
:
"0"
,
"storeId"
:
"0"
,
"value"
:
"2"
,
"value"
:
"2"
,
"id"
:
1
2
"id"
:
1
1
},
},
{
{
"domain"
:
".twitter.com"
,
"domain"
:
".twitter.com"
,
"expirationDate"
:
1757
239567.820814
,
"expirationDate"
:
1757
316314.856452
,
"hostOnly"
:
false
,
"hostOnly"
:
false
,
"httpOnly"
:
false
,
"httpOnly"
:
false
,
"name"
:
"personalization_id"
,
"name"
:
"personalization_id"
,
...
@@ -177,12 +163,12 @@
...
@@ -177,12 +163,12 @@
"secure"
:
true
,
"secure"
:
true
,
"session"
:
false
,
"session"
:
false
,
"storeId"
:
"0"
,
"storeId"
:
"0"
,
"value"
:
"
\"
v1_
ZCUHat1WJYkTwmbDxH++aA
==
\"
"
,
"value"
:
"
\"
v1_
wADam4N8E7iunHX/QZVB6g
==
\"
"
,
"id"
:
1
3
"id"
:
1
2
},
},
{
{
"domain"
:
".twitter.com"
,
"domain"
:
".twitter.com"
,
"expirationDate"
:
17542
22269.877218
,
"expirationDate"
:
17542
92323.952039
,
"hostOnly"
:
false
,
"hostOnly"
:
false
,
"httpOnly"
:
false
,
"httpOnly"
:
false
,
"name"
:
"twid"
,
"name"
:
"twid"
,
...
@@ -191,7 +177,21 @@
...
@@ -191,7 +177,21 @@
"secure"
:
true
,
"secure"
:
true
,
"session"
:
false
,
"session"
:
false
,
"storeId"
:
"0"
,
"storeId"
:
"0"
,
"value"
:
"u%3D1535642152566259712"
,
"value"
:
"u%3D1815666691260702720"
,
"id"
:
13
},
{
"domain"
:
"twitter.com"
,
"expirationDate"
:
1737275644
,
"hostOnly"
:
true
,
"httpOnly"
:
false
,
"name"
:
"g_state"
,
"path"
:
"/"
,
"sameSite"
:
"unspecified"
,
"secure"
:
false
,
"session"
:
false
,
"storeId"
:
"0"
,
"value"
:
"{\"i_l\"
:
0
}
",
"
id
": 14
"
id
": 14
},
},
{
{
...
...
stream.go
View file @
3af78dfd
...
@@ -66,7 +66,7 @@ func TaskIdx(done <-chan interface{}, inStream <-chan taskInterface) (<-chan tas
...
@@ -66,7 +66,7 @@ func TaskIdx(done <-chan interface{}, inStream <-chan taskInterface) (<-chan tas
return
return
case
task
:=
<-
inStream
:
case
task
:=
<-
inStream
:
slog
.
Info
(
"TaskIdx"
,
"task.ID()"
,
task
.
ID
(),
"task.UserName()"
,
task
.
UserName
(),
"task.InitIdx()"
,
task
.
InitIdx
())
slog
.
Info
(
"TaskIdx"
,
"task.
TaskType()"
,
task
.
TaskType
(),
"task.
ID()"
,
task
.
ID
(),
"task.UserName()"
,
task
.
UserName
(),
"task.InitIdx()"
,
task
.
InitIdx
())
if
!
task
.
InitIdx
()
{
if
!
task
.
InitIdx
()
{
...
@@ -79,6 +79,7 @@ func TaskIdx(done <-chan interface{}, inStream <-chan taskInterface) (<-chan tas
...
@@ -79,6 +79,7 @@ func TaskIdx(done <-chan interface{}, inStream <-chan taskInterface) (<-chan tas
case
outListStream
<-
TaskIdAndList
{
case
outListStream
<-
TaskIdAndList
{
TaskId
:
task
.
ID
(),
TaskId
:
task
.
ID
(),
List
:
list
,
List
:
list
,
TaskType
:
task
.
TaskType
(),
}
:
}
:
}
}
...
@@ -99,11 +100,13 @@ func TaskIdx(done <-chan interface{}, inStream <-chan taskInterface) (<-chan tas
...
@@ -99,11 +100,13 @@ func TaskIdx(done <-chan interface{}, inStream <-chan taskInterface) (<-chan tas
}
}
type
TaskIdAndList
struct
{
type
TaskIdAndList
struct
{
TaskType
string
TaskId
string
TaskId
string
List
*
list
.
List
List
*
list
.
List
}
}
type
TaskIdAndProfiles
struct
{
type
TaskIdAndProfiles
struct
{
TaskType
string
TaskId
string
TaskId
string
Profiles
[]
Profile
Profiles
[]
Profile
}
}
...
@@ -138,7 +141,7 @@ func BackListToQueue(done <-chan interface{}, inStream <-chan TaskIdAndList) <-c
...
@@ -138,7 +141,7 @@ func BackListToQueue(done <-chan interface{}, inStream <-chan TaskIdAndList) <-c
c
=
c
+
1
c
=
c
+
1
if
c
%
100
==
0
{
if
c
%
100
==
0
{
fmt
.
Println
(
"BackListToQueue"
,
"len(inStream)"
,
len
(
inStream
),
"len(outStream)"
,
len
(
outStream
))
fmt
.
Println
(
"BackListToQueue"
,
"len(inStream)"
,
len
(
inStream
),
"len(outStream)"
,
len
(
outStream
)
,
"len(res)"
,
len
(
res
)
)
select
{
select
{
case
<-
done
:
case
<-
done
:
...
@@ -146,6 +149,7 @@ func BackListToQueue(done <-chan interface{}, inStream <-chan TaskIdAndList) <-c
...
@@ -146,6 +149,7 @@ func BackListToQueue(done <-chan interface{}, inStream <-chan TaskIdAndList) <-c
case
outStream
<-
TaskIdAndProfiles
{
case
outStream
<-
TaskIdAndProfiles
{
Profiles
:
res
,
Profiles
:
res
,
TaskId
:
users
.
TaskId
,
TaskId
:
users
.
TaskId
,
TaskType
:
users
.
TaskType
,
}
:
}
:
res
=
make
([]
Profile
,
0
,
users
.
List
.
Len
())
res
=
make
([]
Profile
,
0
,
users
.
List
.
Len
())
...
@@ -155,7 +159,7 @@ func BackListToQueue(done <-chan interface{}, inStream <-chan TaskIdAndList) <-c
...
@@ -155,7 +159,7 @@ func BackListToQueue(done <-chan interface{}, inStream <-chan TaskIdAndList) <-c
}
}
}
}
fmt
.
Println
(
"BackListToQueue"
,
"len(inStream)"
,
len
(
inStream
),
"len(outStream)"
,
len
(
outStream
))
fmt
.
Println
(
"BackListToQueue"
,
"len(inStream)"
,
len
(
inStream
),
"len(outStream)"
,
len
(
outStream
)
,
"len(res)"
,
len
(
res
)
)
select
{
select
{
case
<-
done
:
case
<-
done
:
...
@@ -163,6 +167,7 @@ func BackListToQueue(done <-chan interface{}, inStream <-chan TaskIdAndList) <-c
...
@@ -163,6 +167,7 @@ func BackListToQueue(done <-chan interface{}, inStream <-chan TaskIdAndList) <-c
case
outStream
<-
TaskIdAndProfiles
{
case
outStream
<-
TaskIdAndProfiles
{
Profiles
:
res
,
Profiles
:
res
,
TaskId
:
users
.
TaskId
,
TaskId
:
users
.
TaskId
,
TaskType
:
users
.
TaskType
,
}
:
}
:
}
}
...
@@ -197,6 +202,12 @@ func InsertOrUpdateUsers(done <-chan interface{}, inStream <-chan TaskIdAndProfi
...
@@ -197,6 +202,12 @@ func InsertOrUpdateUsers(done <-chan interface{}, inStream <-chan TaskIdAndProfi
//rows := make([]map[string]string, 0, len(users.Profiles))
//rows := make([]map[string]string, 0, len(users.Profiles))
//res, c, err := client.From("followers").Insert(rows, true, "", "representation", "").Execute()
var
res
[]
byte
var
err
error
if
users
.
TaskType
==
FollowType
{
rows
:=
make
([]
Follower
,
0
,
len
(
users
.
Profiles
))
rows
:=
make
([]
Follower
,
0
,
len
(
users
.
Profiles
))
for
_
,
user
:=
range
users
.
Profiles
{
for
_
,
user
:=
range
users
.
Profiles
{
...
@@ -211,29 +222,50 @@ func InsertOrUpdateUsers(done <-chan interface{}, inStream <-chan TaskIdAndProfi
...
@@ -211,29 +222,50 @@ func InsertOrUpdateUsers(done <-chan interface{}, inStream <-chan TaskIdAndProfi
}
}
rows
=
append
(
rows
,
row
)
rows
=
append
(
rows
,
row
)
}
}
res
,
_
,
err
=
client
.
From
(
"followers"
)
.
Insert
(
rows
,
true
,
""
,
"representation"
,
""
)
.
Execute
()
}
//res, c, err := client.From("followers").Insert(rows, true, "", "representation", "").Execute()
if
users
.
TaskType
==
RetweetType
{
rows
:=
make
([]
Retweeter
,
0
,
len
(
users
.
Profiles
))
for
_
,
user
:=
range
users
.
Profiles
{
res
,
_
,
err
:=
client
.
From
(
"followers"
)
.
Insert
(
rows
,
true
,
""
,
"representation"
,
""
)
.
Execute
()
sDec
,
_
:=
b64
.
StdEncoding
.
DecodeString
(
user
.
UserID
)
userId
,
_
:=
strings
.
CutPrefix
(
string
(
sDec
),
"User:"
)
row
:=
Retweeter
{
TweetId
:
users
.
TaskId
,
//string `json:"tweet_id"`
RetweeterId
:
userId
,
//string `json:"retweeter_id"`
RetweeterUserName
:
user
.
Username
,
//string `json:"retweeter_username"`
// Follower: userId,
// UserName: user.Username,
// UserId: users.TaskId,
}
rows
=
append
(
rows
,
row
)
}
res
,
_
,
err
=
client
.
From
(
"retweeters"
)
.
Insert
(
rows
,
true
,
""
,
"representation"
,
""
)
.
Execute
()
}
if
err
!=
nil
{
if
err
!=
nil
{
slog
.
Error
(
"insert into followers"
,
err
)
slog
.
Error
(
"insert into followers
or retweeters
"
,
err
)
for
_
,
user
:=
range
users
.
Profiles
{
for
_
,
user
:=
range
users
.
Profiles
{
usersAsJson
,
err
:=
json
.
Marshal
(
user
)
usersAsJson
,
err
:=
json
.
Marshal
(
user
)
if
err
!=
nil
{
if
err
!=
nil
{
slog
.
Error
(
"insert into followers json.Marshal"
,
err
)
slog
.
Error
(
"insert into followers
or retweeters
json.Marshal"
,
err
)
continue
continue
}
}
sDec
,
_
:=
b64
.
StdEncoding
.
DecodeString
(
user
.
UserID
)
sDec
,
_
:=
b64
.
StdEncoding
.
DecodeString
(
user
.
UserID
)
userId
,
_
:=
strings
.
CutPrefix
(
string
(
sDec
),
"User:"
)
userId
,
_
:=
strings
.
CutPrefix
(
string
(
sDec
),
"User:"
)
slog
.
Error
(
"insert into followers error"
,
string
(
usersAsJson
),
userId
)
slog
.
Error
(
"insert into followers
or retweeters
error"
,
string
(
usersAsJson
),
userId
)
}
}
}
else
{
}
else
{
slog
.
Info
(
"insert into followers"
,
string
(
res
),
err
)
slog
.
Info
(
"insert into followers
or retweeters
"
,
string
(
res
),
err
)
}
}
fmt
.
Println
(
"InsertOrUpdateUsers"
,
"len(inStream)"
,
len
(
inStream
))
fmt
.
Println
(
"InsertOrUpdateUsers"
,
"len(inStream)"
,
len
(
inStream
))
...
@@ -334,7 +366,7 @@ func TaskImplement(done <-chan interface{}, inTaskStream <-chan taskInterface, i
...
@@ -334,7 +366,7 @@ func TaskImplement(done <-chan interface{}, inTaskStream <-chan taskInterface, i
return
return
case
res
:=
<-
inResourceStream
:
case
res
:=
<-
inResourceStream
:
slog
.
Info
(
"TaskImplement"
,
"task.ID()"
,
task
.
ID
(),
"task.UserName()"
,
task
.
UserName
(),
"len(inResourceStream)"
,
len
(
inResourceStream
))
slog
.
Info
(
"TaskImplement"
,
"task.
TaskType()"
,
task
.
TaskType
(),
"task.
ID()"
,
task
.
ID
(),
"task.UserName()"
,
task
.
UserName
(),
"len(inResourceStream)"
,
len
(
inResourceStream
))
if
err
:=
task
.
Fetch
(
res
.
Scraper
);
err
!=
nil
{
if
err
:=
task
.
Fetch
(
res
.
Scraper
);
err
!=
nil
{
slog
.
Error
(
"task.Fetch"
,
"err"
,
err
.
Error
())
slog
.
Error
(
"task.Fetch"
,
"err"
,
err
.
Error
())
...
...
stream_idx.go
View file @
3af78dfd
...
@@ -44,6 +44,18 @@ type Follower struct {
...
@@ -44,6 +44,18 @@ type Follower struct {
UserName
string
`json:"follower_username"`
UserName
string
`json:"follower_username"`
}
}
type
RetweeterId
struct
{
Retweeter
Id
int
`json:"id"`
CreatedAt
string
`json:"created_at"`
}
type
Retweeter
struct
{
TweetId
string
`json:"tweet_id"`
RetweeterId
string
`json:"retweeter_id"`
RetweeterUserName
string
`json:"retweeter_username"`
}
func
GetTasksIdx
()
([]
taskInterface
,
error
)
{
func
GetTasksIdx
()
([]
taskInterface
,
error
)
{
tasks
,
err
:=
QueryAllTask
()
tasks
,
err
:=
QueryAllTask
()
...
@@ -82,19 +94,55 @@ func GetTasksIdx() ([]taskInterface, error) {
...
@@ -82,19 +94,55 @@ func GetTasksIdx() ([]taskInterface, error) {
return
nil
,
err
return
nil
,
err
}
}
followTask
:=
NewFollowTask
(
task
.
TaskId
,
task
.
User
)
followTask
:=
NewFollowTask
(
task
.
TaskId
,
task
.
User
,
task
.
TaskType
)
followTask
.
Idx
=
userRes
followTask
.
Idx
=
userRes
if
len
(
userRes
)
==
0
{
//
if len(userRes) == 0 {
followTask
.
Init
=
true
//
followTask.Init = true
}
//
}
res
=
append
(
res
,
followTask
)
res
=
append
(
res
,
followTask
)
}
}
if
task
.
TaskType
==
RetweetType
{
if
task
.
TaskType
==
RetweetType
{
data
,
count
,
err
:=
client
.
From
(
"retweeters"
)
.
Select
(
""
,
"tweet_id"
,
false
)
.
Eq
(
"tweet_id"
,
task
.
TaskId
)
.
Order
(
"id"
,
&
postgrest
.
OrderOpts
{
Ascending
:
false
,
// NullsFirst bool
// ForeignTable string
})
.
Range
(
0
,
10
,
""
)
.
Execute
()
if
err
!=
nil
{
slog
.
Error
(
"select * from retweeters error"
,
err
)
return
nil
,
err
}
_
=
count
slog
.
Info
(
"idx data"
,
"tweet id"
,
task
.
TaskId
,
"user name"
,
task
.
User
,
"idx"
,
data
)
fmt
.
Println
(
"idx data"
,
string
(
data
))
userRes
:=
make
([]
RetweeterId
,
0
,
10
)
if
err
:=
json
.
Unmarshal
(
data
,
&
userRes
);
err
!=
nil
{
return
nil
,
err
}
retweetTask
:=
NewRetweetTask
(
task
.
TaskId
,
task
.
User
,
task
.
TaskType
)
//followTask := NewFollowTask(task.TaskId, task.User, task.TaskType)
retweetTask
.
Idx
=
userRes
// if len(userRes) == 0 {
// followTask.Init = true
// }
res
=
append
(
res
,
retweetTask
)
}
}
}
}
...
...
task.go
View file @
3af78dfd
package
main
package
main
import
(
import
(
"net/http"
"os"
"strings"
"strings"
"time"
"time"
b64
"encoding/base64"
b64
"encoding/base64"
"encoding/json"
twitterscraper
"github.com/imperatrona/twitter-scraper"
twitterscraper
"github.com/imperatrona/twitter-scraper"
)
)
...
@@ -122,19 +119,19 @@ func InitScraper(user, password string) (*twitterscraper.Scraper, error) {
...
@@ -122,19 +119,19 @@ func InitScraper(user, password string) (*twitterscraper.Scraper, error) {
//err := scraper3.Login("Wade_Leeeee", "923881393time")
//err := scraper3.Login("Wade_Leeeee", "923881393time")
//
if err := scraper3.Login(user, password); err != nil {
if
err
:=
scraper3
.
Login
(
user
,
password
);
err
!=
nil
{
//
return nil, err
return
nil
,
err
//
}
}
// Deserialize from JSON
// Deserialize from JSON
var
cookies
[]
*
http
.
Cookie
//
var cookies []*http.Cookie
f
,
_
:=
os
.
Open
(
"cookies.json"
)
//
f, _ := os.Open("cookies.json")
json
.
NewDecoder
(
f
)
.
Decode
(
&
cookies
)
//
json.NewDecoder(f).Decode(&cookies)
scraper3
.
SetCookies
(
cookies
)
//
scraper3.SetCookies(cookies)
if
!
scraper3
.
IsLoggedIn
()
{
//
if !scraper3.IsLoggedIn() {
panic
(
"Invalid cookies"
)
//
panic("Invalid cookies")
}
//
}
return
scraper3
,
nil
return
scraper3
,
nil
...
...
type.go
View file @
3af78dfd
...
@@ -38,7 +38,8 @@ type NewTask[T FollowTask | RetweetTask] struct {
...
@@ -38,7 +38,8 @@ type NewTask[T FollowTask | RetweetTask] struct {
type
FollowTask
struct
{
type
FollowTask
struct
{
// URL string
// URL string
Init
bool
//Init bool
TaskTypeStr
string
UserIdStr
string
UserIdStr
string
UserNameStr
string
UserNameStr
string
Next
string
Next
string
...
@@ -51,21 +52,24 @@ type FollowTask struct {
...
@@ -51,21 +52,24 @@ type FollowTask struct {
//Scraper *twitterscraper.Scraper
//Scraper *twitterscraper.Scraper
}
}
func
NewFollowTask
(
userId
,
userName
string
)
*
FollowTask
{
func
NewFollowTask
(
userId
,
userName
,
taskType
string
)
*
FollowTask
{
return
&
FollowTask
{
return
&
FollowTask
{
backPushPop
:
list
.
New
(),
backPushPop
:
list
.
New
(),
Idx
:
make
([]
FollowerId
,
0
),
Idx
:
make
([]
FollowerId
,
0
),
UserIdStr
:
userId
,
UserIdStr
:
userId
,
UserNameStr
:
userName
,
UserNameStr
:
userName
,
TaskTypeStr
:
taskType
,
}
}
}
}
type
taskInterface
interface
{
type
taskInterface
interface
{
TaskType
()
string
ID
()
string
ID
()
string
UserName
()
string
UserName
()
string
Fetch
(
scraper
*
twitterscraper
.
Scraper
)
error
Fetch
(
scraper
*
twitterscraper
.
Scraper
)
error
InitIdx
()
bool
InitIdx
()
bool
UpdateIdx
()
(
*
list
.
List
,
bool
)
UpdateIdx
()
(
*
list
.
List
,
bool
)
}
}
...
@@ -82,6 +86,10 @@ func (f *FollowTask) InitIdx() bool {
...
@@ -82,6 +86,10 @@ func (f *FollowTask) InitIdx() bool {
return
true
return
true
}
}
func
(
f
*
FollowTask
)
TaskType
()
string
{
return
f
.
TaskTypeStr
}
func
(
f
*
FollowTask
)
ID
()
string
{
func
(
f
*
FollowTask
)
ID
()
string
{
return
f
.
UserIdStr
return
f
.
UserIdStr
}
}
...
@@ -155,6 +163,25 @@ func MatchIdx(data Users, idxs []FollowerId) ([]Profile, bool) {
...
@@ -155,6 +163,25 @@ func MatchIdx(data Users, idxs []FollowerId) ([]Profile, bool) {
return
data
.
Profiles
,
false
return
data
.
Profiles
,
false
}
}
func
MatchIdxRetweet
(
data
Users
,
idxs
[]
RetweeterId
)
([]
Profile
,
bool
)
{
if
len
(
idxs
)
==
0
{
return
data
.
Profiles
,
true
}
for
k
,
v
:=
range
data
.
Profiles
{
for
_
,
idx
:=
range
idxs
{
if
v
.
UserIdAsNumber
==
idx
.
Retweeter
.
RetweeterId
{
//if v.UserIdAsNumber == idx.Follower.Follower {
return
data
.
Profiles
[
:
k
],
true
}
}
}
return
data
.
Profiles
,
false
}
func
(
f
*
FollowTask
)
Fetch
(
scraper
*
twitterscraper
.
Scraper
)
error
{
func
(
f
*
FollowTask
)
Fetch
(
scraper
*
twitterscraper
.
Scraper
)
error
{
// f.UserId = "OnlyDD_D"
// f.UserId = "OnlyDD_D"
...
@@ -176,6 +203,8 @@ func (f *FollowTask) Fetch(scraper *twitterscraper.Scraper) error {
...
@@ -176,6 +203,8 @@ func (f *FollowTask) Fetch(scraper *twitterscraper.Scraper) error {
UserIdAsNumber
:
userId
,
UserIdAsNumber
:
userId
,
Profile
:
v
,
Profile
:
v
,
}
}
//slog.Info("fetch-----------------", item.UserID, item.Profile.Username, item.Profile.Joined)
usersWithUserNumber
=
append
(
usersWithUserNumber
,
item
)
usersWithUserNumber
=
append
(
usersWithUserNumber
,
item
)
}
}
...
@@ -195,19 +224,39 @@ func (f *FollowTask) Fetch(scraper *twitterscraper.Scraper) error {
...
@@ -195,19 +224,39 @@ func (f *FollowTask) Fetch(scraper *twitterscraper.Scraper) error {
type
RetweetTask
struct
{
type
RetweetTask
struct
{
//URL string
//URL string
TaskTypeStr
string
TweetId
string
TweetId
string
UserNameStr
string
UserNameStr
string
Next
string
Next
string
Idx
[]
FollowerId
Idx
[]
RetweeterId
//[]RetweeterId
// backPushPop = list.New()
// backPushPop = list.New()
backPushPop
list
.
List
backPushPop
*
list
.
List
NewIdx
[]
RetweeterId
Res
Users
}
}
// func (r *RetweetTask) URl() string {
// func (r *RetweetTask) URl() string {
// return r.URL
// return r.URL
// }
// }
func
NewRetweetTask
(
Id
,
userName
,
taskType
string
)
*
RetweetTask
{
return
&
RetweetTask
{
TaskTypeStr
:
taskType
,
TweetId
:
Id
,
UserNameStr
:
userName
,
backPushPop
:
list
.
New
(),
Idx
:
make
([]
RetweeterId
,
0
),
}
}
func
(
f
*
RetweetTask
)
TaskType
()
string
{
return
f
.
TaskTypeStr
}
func
(
f
*
RetweetTask
)
UserName
()
string
{
func
(
f
*
RetweetTask
)
UserName
()
string
{
return
f
.
UserNameStr
return
f
.
UserNameStr
}
}
...
@@ -222,7 +271,43 @@ func (f *RetweetTask) ID() string {
...
@@ -222,7 +271,43 @@ func (f *RetweetTask) ID() string {
func
(
f
*
RetweetTask
)
Fetch
(
scraper
*
twitterscraper
.
Scraper
)
error
{
func
(
f
*
RetweetTask
)
Fetch
(
scraper
*
twitterscraper
.
Scraper
)
error
{
return
scraper
.
RetweetsUsers
(
f
.
TweetId
)
slog
.
Info
(
"retweet fetch"
,
"f.TweetId"
,
f
.
TweetId
,
"f.UserNameStr"
,
f
.
UserNameStr
,
"f.Next"
,
f
.
Next
)
//return scraper.RetweetsUsers(f.TweetId)
users
,
newNext
,
err
:=
scraper
.
RetweetsUsers
(
f
.
TweetId
,
20
,
f
.
Next
)
//users, newNext, err := scraper.FetchFollowers(f.UserId, 20, f.Next)
if
err
!=
nil
{
return
err
}
usersWithUserNumber
:=
make
([]
Profile
,
0
,
len
(
users
))
for
_
,
v
:=
range
users
{
sDec
,
_
:=
b64
.
StdEncoding
.
DecodeString
(
v
.
UserID
)
userId
,
_
:=
strings
.
CutPrefix
(
string
(
sDec
),
"User:"
)
item
:=
Profile
{
UserIdAsNumber
:
userId
,
Profile
:
v
,
}
//slog.Info("fetch-----------------", item.UserID, item.Profile.Username, item.Profile.Joined)
usersWithUserNumber
=
append
(
usersWithUserNumber
,
item
)
}
res
:=
Users
{
Profiles
:
usersWithUserNumber
,
Current
:
f
.
Next
,
Next
:
newNext
,
}
slog
.
Info
(
"retweet fetch"
,
"f.TweetId"
,
f
.
TweetId
,
"f.UserNameStr"
,
f
.
UserNameStr
,
"res.Current"
,
res
.
Current
,
"res.Next"
,
res
.
Next
,
"len(res.Profiles)"
,
len
(
res
.
Profiles
))
f
.
Res
=
res
return
nil
}
}
...
@@ -232,11 +317,56 @@ func (f *RetweetTask) Fetch(scraper *twitterscraper.Scraper) error {
...
@@ -232,11 +317,56 @@ func (f *RetweetTask) Fetch(scraper *twitterscraper.Scraper) error {
func
(
f
*
RetweetTask
)
InitIdx
()
bool
{
func
(
f
*
RetweetTask
)
InitIdx
()
bool
{
return
f
.
Idx
==
nil
||
len
(
f
.
Idx
)
==
0
if
len
(
f
.
Res
.
Profiles
)
>
0
{
return
false
}
return
true
}
}
func
(
f
*
RetweetTask
)
UpdateIdx
()
(
*
list
.
List
,
bool
)
{
func
(
f
*
RetweetTask
)
UpdateIdx
()
(
*
list
.
List
,
bool
)
{
if
len
(
f
.
NewIdx
)
==
0
{
for
k
,
v
:=
range
f
.
Res
.
Profiles
{
f
.
NewIdx
=
append
(
f
.
NewIdx
,
RetweeterId
{
Retweeter
:
Retweeter
{
RetweeterId
:
v
.
UserIdAsNumber
,
RetweeterUserName
:
v
.
Username
,
},
})
if
k
>
5
{
break
}
}
}
profiles
,
ok
:=
MatchIdxRetweet
(
f
.
Res
,
f
.
Idx
)
for
_
,
v
:=
range
profiles
{
f
.
backPushPop
.
PushFront
(
v
)
}
slog
.
Info
(
"MatchIdx"
,
"f.TweetId"
,
f
.
TweetId
,
"f.UserNameStr"
,
f
.
UserNameStr
,
"match"
,
ok
,
"len(profiles)"
,
len
(
profiles
))
if
!
ok
{
f
.
Next
=
f
.
Res
.
Next
return
nil
,
false
}
// 这个想一想
if
f
.
backPushPop
.
Len
()
==
0
{
f
.
Next
=
""
//time.Sleep(time.Second * 20)
return
nil
,
false
return
nil
,
false
}
f
.
Idx
=
f
.
NewIdx
f
.
NewIdx
=
make
([]
RetweeterId
,
0
,
len
(
f
.
Idx
))
resList
:=
f
.
backPushPop
f
.
backPushPop
=
list
.
New
()
return
resList
,
true
}
}
type
TwitterAccount
struct
{
type
TwitterAccount
struct
{
...
...
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