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
2d92293a
Commit
2d92293a
authored
Aug 20, 2024
by
Ubuntu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix restart task
parent
7bc8253a
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
99 additions
and
4 deletions
+99
-4
accounts.go
accounts.go
+37
-0
accounts_test.go
accounts_test.go
+17
-0
api_db.go
api_db.go
+2
-2
api_db_test.go
api_db_test.go
+30
-0
api_service.go
api_service.go
+10
-1
client.go
client.go
+1
-1
syncer
syncer
+0
-0
task.go
task.go
+2
-0
No files found.
accounts.go
0 → 100644
View file @
2d92293a
package
main
import
"encoding/json"
type
Account
struct
{
Username
string
`json:"username"`
Password
string
`json:"password"`
Email
string
`json:"email"`
Cookies
[]
byte
`json:"cookies"`
Available
bool
`json:"available"`
}
func
GetAvailableAccounts
()
([]
Account
,
error
)
{
data
,
count
,
err
:=
client
.
From
(
"accounts"
)
.
Select
(
"*"
,
"exact"
,
false
)
.
Eq
(
"available"
,
"true"
)
.
Execute
()
if
err
!=
nil
{
return
nil
,
err
}
//return count == 1, nil
_
=
count
res
:=
make
([]
Account
,
0
,
count
)
if
err
:=
json
.
Unmarshal
(
data
,
&
res
);
err
!=
nil
{
return
nil
,
err
}
return
res
,
nil
}
func
UpdateCookies
(
username
string
,
cookies
[]
byte
)
error
{
return
nil
}
accounts_test.go
0 → 100644
View file @
2d92293a
package
main
import
"testing"
func
TestAccounts
(
t
*
testing
.
T
)
{
accounts
,
err
:=
GetAvailableAccounts
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
for
k
,
v
:=
range
accounts
{
t
.
Log
(
k
,
v
)
}
}
api_db.go
View file @
2d92293a
...
...
@@ -45,7 +45,7 @@ func AddTaskInsert(req AddTaskReq) error {
Stop
:
false
,
}
res
,
_
,
err
:=
client
.
From
(
"tasks"
)
.
Insert
(
task
,
fals
e
,
""
,
"representation"
,
""
)
.
Execute
()
res
,
_
,
err
:=
client
.
From
(
"tasks"
)
.
Insert
(
task
,
tru
e
,
""
,
"representation"
,
""
)
.
Execute
()
_
=
res
...
...
@@ -108,7 +108,7 @@ func QueryProjectByKeysAndToken(cfg ProjectReq) (bool, error) {
}
func
CheckTask
(
userId
,
taskId
,
taskType
string
)
(
bool
,
error
)
{
func
CheckTask
Exist
(
userId
,
taskId
,
taskType
string
)
(
bool
,
error
)
{
_
,
count
,
err
:=
client
.
From
(
"tasks"
)
.
Select
(
"*"
,
"exact"
,
false
)
.
Eq
(
"user_id"
,
userId
)
.
Eq
(
"task_id"
,
taskId
)
.
Eq
(
"task_type"
,
taskType
)
.
Eq
(
"stop"
,
"false"
)
.
Execute
()
...
...
api_db_test.go
0 → 100644
View file @
2d92293a
package
main
import
(
"testing"
"time"
)
func
TestTime
(
t
*
testing
.
T
)
{
data
,
count
,
err
:=
client
.
From
(
"tweet_liking_users"
)
.
Select
(
"*"
,
"exact"
,
false
)
.
Eq
(
"task_id"
,
"1800805503066661056"
)
.
Eq
(
"user_id"
,
"1823984946710765569"
)
.
Gt
(
"created_at"
,
"2024-08-17T13:18:18.505072+00:00"
)
.
Lt
(
"created_at"
,
"2024-08-18T13:18:19.505072+00:00"
)
.
Execute
()
if
err
!=
nil
{
t
.
Fatal
(
err
.
Error
())
}
t
.
Log
(
string
(
data
))
t
.
Log
(
count
)
//return count == 1, nil
//2006-01-02 15:04:05
//2024-01-01T00:00:00Z
parseTime
,
err
:=
time
.
Parse
(
"2006-01-02T15:04:05Z"
,
"2024-01-01T00:00:06Z"
)
if
err
!=
nil
{
t
.
Fatal
(
err
.
Error
())
}
t
.
Log
(
parseTime
.
String
())
t
.
Log
(
parseTime
.
Format
(
"2006-01-02T15:04:05.000000+00:00"
))
}
api_service.go
View file @
2d92293a
...
...
@@ -183,7 +183,7 @@ func TaskAdd(c *fiber.Ctx) error {
})
}
ok
,
err
=
CheckTask
(
req
.
User
,
req
.
TaskId
,
req
.
TaskType
)
ok
,
err
=
CheckTask
Exist
(
req
.
User
,
req
.
TaskId
,
req
.
TaskType
)
if
err
!=
nil
{
return
c
.
JSON
(
Res
{
...
...
@@ -222,6 +222,8 @@ func TaskAdd(c *fiber.Ctx) error {
})
}
slog
.
Info
(
"add task into db"
,
"user"
,
req
.
User
,
"TaskType"
,
req
.
TaskType
,
"TaskId"
,
req
.
TaskId
)
// req.AddOrStop = true
err
=
AddTaskInsert
(
req
)
...
...
@@ -264,6 +266,8 @@ func TaskStop(c *fiber.Ctx) error {
})
}
slog
.
Info
(
"stop job"
,
"user"
,
req
.
User
,
"TaskType"
,
req
.
TaskType
,
"TaskId"
,
req
.
TaskId
)
if
err
:=
Worker
.
StopJob
(
req
.
User
,
req
.
TaskType
);
err
!=
nil
{
return
c
.
JSON
(
Res
{
Code
:
500
,
...
...
@@ -271,6 +275,8 @@ func TaskStop(c *fiber.Ctx) error {
})
}
slog
.
Info
(
"set stop to true in db"
,
"user"
,
req
.
User
,
"TaskType"
,
req
.
TaskType
,
"TaskId"
,
req
.
TaskId
)
err
:=
StopTaskUpdate
(
req
)
if
err
!=
nil
{
...
...
@@ -293,6 +299,9 @@ func VerifyRetweeter(c *fiber.Ctx) error {
tweetId
:=
c
.
Query
(
"tweet_id"
)
retweeterId
:=
c
.
Query
(
"retweeter_id"
)
// beginTime := c.Query("begin_time")
// endTime := c.Query("end_time")
if
len
(
tweetId
)
==
0
||
len
(
retweeterId
)
==
0
{
slog
.
Error
(
"VerifyFollower"
,
"tweetId"
,
tweetId
,
"retweeterId"
,
retweeterId
)
return
c
.
JSON
(
Res
{
...
...
client.go
View file @
2d92293a
...
...
@@ -192,7 +192,7 @@ func (c *Client) TweetLikingUsers(tweetId string, next string) ([]*twitter.UserO
}
func
(
c
*
Client
)
Usag
e
()
(
map
[
string
]
*
twitter
.
UserDictionary
,
error
)
{
func
(
c
*
Client
)
M
e
()
(
map
[
string
]
*
twitter
.
UserDictionary
,
error
)
{
// ctx is generated here only to use with Ratelimiter
// TODO: Fix performance by removing unneeded allocaton here
...
...
syncer
View file @
2d92293a
No preview for this file type
task.go
View file @
2d92293a
...
...
@@ -27,6 +27,8 @@ func (w *Work) StopJob(userId, taskType string) error {
if
v
,
ok
:=
w
.
Task
[
userId
+
"-"
+
taskType
];
ok
{
close
(
v
)
delete
(
w
.
Task
,
userId
+
"-"
+
taskType
)
}
else
{
return
fmt
.
Errorf
(
"%s do not run"
,
userId
+
"-"
+
taskType
)
}
...
...
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