Skip to content

Commit

Permalink
autopush@1483370671
Browse files Browse the repository at this point in the history
  • Loading branch information
denkhaus committed Jan 2, 2017
1 parent c8623d6 commit 690f458
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cypher.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (
MATCH
(a:TwitterUser)
WHERE
EXISTS(a.following_upd) AND a.following <> 0
EXISTS(a.following_upd) AND a.following <> 0 AND NOT a.protected
WITH
a, size((a)-[:FOLLOWS]->()) as following_count
WHERE
Expand All @@ -44,7 +44,7 @@ const (
MATCH
(a:TwitterUser)
WHERE
EXISTS(a.followers_upd) AND a.followers <> 0
EXISTS(a.followers_upd) AND a.followers <> 0 AND NOT a.protected
WITH
a, size(()-[:FOLLOWS]->(a)) as followers_count
WHERE
Expand All @@ -61,6 +61,11 @@ const (
DELETE rel
`

CYPHER_USER_SET_PROTECTED = `
MATCH (n1:TwitterUser {id:{id}})
SET n1.protected = true
`

CYPHER_REMOVE_FOLLOWERS_REL = `
MATCH (TwitterUser {id:{id}})<-[rel:FOLLOWS]-()
DELETE rel
Expand Down Expand Up @@ -111,6 +116,7 @@ const (
SET
user.id = u.id_str,
user.name = u.name,
user.protected = u.protected,
user.created_at = u.created_at,
user.location = u.location,
user.followers = u.followers_count,
Expand All @@ -133,6 +139,7 @@ const (
SET
user.screen_name = u.screen_name,
user.name = u.name,
user.protected = u.protected,
user.created_at = u.created_at,
user.location = u.location,
user.followers = u.followers_count,
Expand Down
22 changes: 22 additions & 0 deletions graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ func (p *Engine) maintainFollowing(db *neoism.Database) error {
time.Sleep(dur)
break
} else if apiErr.StatusCode > 400 {

if apiErr.StatusCode == 401 {
logger.Infof("mark user #%s as protected", idStr)
_, err = p.execQuery(db, CYPHER_USER_SET_PROTECTED, neoism.Props{
"id": idStr,
})
if err != nil {
return errors.Annotate(err, "set user protected")
}
}

logger.Warnf("received error code %d", apiErr.StatusCode)
break
}
Expand Down Expand Up @@ -155,6 +166,17 @@ func (p *Engine) maintainFollowers(db *neoism.Database) error {
time.Sleep(dur)
break
} else if apiErr.StatusCode > 400 {

if apiErr.StatusCode == 401 {
logger.Infof("mark user #%s as protected", idStr)
_, err = p.execQuery(db, CYPHER_USER_SET_PROTECTED, neoism.Props{
"id": idStr,
})
if err != nil {
return errors.Annotate(err, "set user protected")
}
}

logger.Warnf("received error code %d", apiErr.StatusCode)
break
}
Expand Down

0 comments on commit 690f458

Please sign in to comment.