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
79b0651f
Commit
79b0651f
authored
Dec 01, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update status check
parent
e236b8db
Pipeline
#18300
passed with stage
in 38 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
10 deletions
+44
-10
Dockerfile
Dockerfile
+1
-1
backend_requests.py
backend_requests.py
+43
-9
No files found.
Dockerfile
View file @
79b0651f
...
...
@@ -6,4 +6,4 @@ RUN pip install -r requirements.txt
COPY
./backend_requests.py ./app.py
COPY
. ./
CMD
["gunicorn", "--workers=
2
", "-b", "0.0.0.0:80", "app:app"]
CMD
["gunicorn", "--workers=
1
", "-b", "0.0.0.0:80", "app:app"]
backend_requests.py
View file @
79b0651f
from
flask
import
Flask
from
flask
import
Flask
,
Response
from
flask_cors
import
CORS
from
requests_oauthlib
import
OAuth1Session
,
OAuth2Session
import
os
import
time
import
json
from
get_graphql_endpoint
import
endpoint
import
threading
app
=
Flask
(
__name__
)
CORS
(
app
)
TWITTER_AUTH_KEY
=
'AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs
%3
D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA'
print
(
"Booting"
)
ENDPOINT
=
endpoint
()
print
(
"Booted"
)
FeaturesDict
=
{
"responsive_web_uc_gql_enabled"
:
False
,
...
...
@@ -34,9 +38,41 @@ FeaturesDict = {
}
FeaturesJson
=
json
.
dumps
(
FeaturesDict
)
healthLock
=
threading
.
Lock
()
isHealthy
=
True
def
getTwitterSession
():
twitter_b
=
OAuth2Session
()
twitter_b
.
headers
[
"Authorization"
]
=
"Bearer {}"
.
format
(
TWITTER_AUTH_KEY
)
return
twitter_b
def
doSearch
(
screen_name
,
twitter_b
):
global
isHealthy
searchurl_v2
=
"https://api.twitter.com/2/search/adaptive.json"
params_v2
=
{
"q"
:
"from:@{}"
.
format
(
screen_name
),
"count"
:
1
,
"spelling_corrections"
:
0
,
"tweet_search_mode"
:
"live"
}
search_v2
=
twitter_b
.
get
(
searchurl_v2
,
params
=
params_v2
)
.
json
()
isHealthy
=
'globalObjects'
in
search_v2
if
isHealthy
:
return
search_v2
[
"globalObjects"
][
"tweets"
]
else
:
print
(
"Rate limit occurred, marking as unavailable."
)
return
None
@
app
.
route
(
'/_healthy'
)
def
healthy
():
return
{
"healthy"
:
True
}
result
=
None
if
isHealthy
:
return
{
'healthy'
:
True
}
with
healthLock
:
if
isHealthy
:
return
{
'healthy'
:
True
}
doSearch
(
'Dream'
,
getTwitterSession
())
if
isHealthy
:
print
(
"Rate limit passed."
)
return
{
'healthy'
:
True
}
return
Response
(
status
=
500
)
return
result
@
app
.
route
(
"/<screen_name>"
)
def
searchban
(
screen_name
):
...
...
@@ -63,8 +99,7 @@ def searchban(screen_name):
# twitter = OAuth1Session(TWITTER_IPHONE_CK, TWITTER_IPHONE_CS)
twitter_b
=
OAuth2Session
()
twitter_b
.
headers
[
"Authorization"
]
=
"Bearer {}"
.
format
(
TWITTER_AUTH_KEY
)
twitter_b
=
getTwitterSession
()
# check rate limit
# response = twitter_b.get("https://api.twitter.com/1.1/application/rate_limit_status.json")
...
...
@@ -160,11 +195,10 @@ def searchban(screen_name):
# else:
# return returnjson
searchurl_v2
=
"https://api.twitter.com/2/search/adaptive.json"
params_v2
=
{
"q"
:
"from:@{}"
.
format
(
screen_name
),
"count"
:
1
,
"spelling_corrections"
:
0
,
"tweet_search_mode"
:
"live"
}
search_v2
=
twitter_b
.
get
(
searchurl_v2
,
params
=
params_v2
)
.
json
()
search_tweets
=
search_v2
[
"globalObjects"
][
"tweets"
]
if
search_tweets
==
{}:
search_tweets
=
doSearch
(
screen_name
,
twitter_b
)
if
search_tweets
is
None
:
returnjson
[
"tests"
][
"search"
]
=
'_error'
elif
search_tweets
==
{}:
returnjson
[
"tests"
][
"search"
]
=
False
# returnjson["tests"]["typeahead"] = False
else
:
...
...
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