Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
shadowban-eu-backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
shadowban-eu-backend
Commits
87dc9b18
Commit
87dc9b18
authored
Jan 19, 2023
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add redis
parent
966024be
Pipeline
#19674
passed with stage
in 27 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
3 deletions
+31
-3
backend_requests.py
backend_requests.py
+30
-3
requirements.txt
requirements.txt
+1
-0
No files found.
backend_requests.py
View file @
87dc9b18
...
...
@@ -7,7 +7,18 @@ import json
from
get_graphql_endpoint
import
endpoint
import
threading
import
random
import
redis
redisClient
=
None
if
os
.
getenv
(
'REDIS_HOST'
):
redisPool
=
redis
.
ConnectionPool
(
host
=
os
.
getenv
(
'REDIS_HOST'
),
port
=
os
.
getenv
(
'REDIS_PORT'
,
6379
),
password
=
os
.
getenv
(
'REDIS_PASSWORD'
,
None
),
db
=
os
.
getenv
(
'REDIS_DB'
,
0
)
)
redisClient
=
redis
.
Redis
(
connection_pool
=
redisPool
)
app
=
Flask
(
__name__
)
CORS
(
app
)
...
...
@@ -125,6 +136,13 @@ def healthy():
@
app
.
route
(
"/<screen_name>"
)
def
searchban
(
screen_name
):
if
redisClient
:
cached
=
redisClient
.
get
(
'shadowban:{}'
.
format
(
screen_name
))
if
cached
:
print
(
'Using cached result for {}: {}'
.
format
(
screen_name
,
cached
))
cachedDict
=
json
.
loads
(
cached
)
return
cachedDict
print
(
"Checking {}"
.
format
(
screen_name
))
returnjson
=
{
"timestamp"
:
time
.
time
(),
...
...
@@ -233,6 +251,7 @@ def searchban(screen_name):
"ghost"
:
{
"ban"
:
None
},
"more_replies"
:
{
"ban"
:
False
,
"tweet"
:
"-1"
,
"in_reply_to"
:
"-1"
}
}
hasFailure
=
False
# searchurl = "https://api.twitter.com/1.1/users/search.json"
# params = {"q": "from:@{}".format(screen_name), "count": 1}
...
...
@@ -244,7 +263,7 @@ def searchban(screen_name):
# else:
# return returnjson
print
(
"Checking search suggestion banned of {}"
.
format
(
screen_name
))
suggestions
=
twitter_b
.
get
(
"https://api.twitter.com/1.1/search/typeahead.json?src=search_box&result_type=users&q=@"
+
screen_name
)
.
json
()
try
:
returnjson
[
"tests"
][
"typeahead"
]
=
len
([
1
for
user
in
suggestions
[
"users"
]
if
user
[
"screen_name"
]
.
lower
()
==
screen_name
.
lower
()])
>
0
...
...
@@ -252,16 +271,21 @@ def searchban(screen_name):
returnjson
[
"tests"
][
"typeahead"
]
=
False
if
returnjson
[
"tests"
][
"typeahead"
]
==
False
:
print
(
"{} is search suggestion banned, checking search ban."
.
format
(
screen_name
))
search_tweets
=
doSearch
(
screen_name
,
twitter_b
)
if
search_tweets
is
None
:
returnjson
[
"tests"
][
"search"
]
=
'_error'
hasFailure
=
True
elif
search_tweets
==
{}:
returnjson
[
"tests"
][
"search"
]
=
False
print
(
"{} is search banned."
.
format
(
screen_name
))
# returnjson["tests"]["typeahead"] = False
else
:
returnjson
[
"tests"
][
"search"
]
=
str
(
search_tweets
[
list
(
search_tweets
.
keys
())[
0
]][
"id"
])
print
(
"{} is not search banned."
.
format
(
screen_name
))
else
:
returnjson
[
"tests"
][
"search"
]
=
"_implied_good"
print
(
"{} is not search suggestion banned, skipped search ban check."
.
format
(
screen_name
))
## get replies
## Start GraphQL
...
...
@@ -413,15 +437,18 @@ def searchban(screen_name):
print
(
"Response: "
+
replies
.
text
)
returnjson
[
"tests"
][
"ghost"
]
=
{}
returnjson
[
"tests"
][
"more_replies"
]
=
{}
hasFailure
=
True
#print("ban" in returnjson["tests"]["more_replies"])
#print("ban" in returnjson["tests"]["ghost"])
#print(returnjson["tests"]["ghost"])
plainJson
=
json
.
dumps
(
returnjson
)
print
(
"Result of {}: {}"
.
format
(
screen_name
,
json
.
dumps
(
returnjson
)))
print
(
"Result of {}: {}"
.
format
(
screen_name
,
plainJson
))
if
redisClient
and
not
hasFailure
:
redisClient
.
set
(
"shadowban:{}"
.
format
(
screen_name
),
plainJson
,
ex
=
600
)
return
returnjson
if
__name__
==
'__main__'
:
...
...
requirements.txt
View file @
87dc9b18
...
...
@@ -2,3 +2,4 @@ flask
flask_cors
requests_oauthlib
gunicorn
redis
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