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
98f2494c
Commit
98f2494c
authored
Mar 22, 2024
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add cookie check
parent
ae5b4c9f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
7 deletions
+63
-7
backend_requests.py
backend_requests.py
+63
-7
No files found.
backend_requests.py
View file @
98f2494c
import
sys
from
flask
import
Flask
,
Response
from
flask_cors
import
CORS
from
requests_oauthlib
import
OAuth1Session
,
OAuth2Session
...
...
@@ -39,12 +40,12 @@ if cookie_file:
with
open
(
cookie_file
,
'r'
)
as
f
:
cookies
=
str
.
strip
(
f
.
read
())
.
split
(
"
\n
"
)
print
(
"Booting"
)
#
print("Booting")
ENDPOINT
=
{
"UserTweetsAndReplies"
:
"CwLU7qTfeu0doqhSr6tW4A"
,
"TweetDetail"
:
"BoHLKeBvibdYDiJON1oqTg"
,
}
print
(
"Booted"
)
#
print("Booted")
FeaturesDict
=
{
"responsive_web_uc_gql_enabled"
:
False
,
...
...
@@ -73,11 +74,15 @@ FeaturesJson = json.dumps(FeaturesDict)
healthLock
=
threading
.
Lock
()
isHealthy
=
True
def
getTwitterSession
(
useCooki
e
):
def
getTwitterSession
(
specifyCookie
=
Non
e
):
twitter_b
=
OAuth2Session
()
twitter_b
.
headers
[
"Authorization"
]
=
"Bearer {}"
.
format
(
random
.
choice
(
twitterKeys
))
twitter_b
.
headers
[
'user-agent'
]
=
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36"
cookie
=
random
.
choice
(
cookies
)
cookie
=
''
if
specifyCookie
is
not
None
:
cookie
=
specifyCookie
else
:
cookie
=
random
.
choice
(
cookies
)
if
cookie
:
# and useCookie:
twitter_b
.
headers
[
'cookie'
]
=
cookie
twitter_b
.
headers
[
'x-csrf-token'
]
=
cookie
.
split
(
"ct0="
)[
1
]
.
split
(
";"
)[
0
]
...
...
@@ -85,7 +90,7 @@ def getTwitterSession(useCookie):
def
doSearch
(
screen_name
):
global
isHealthy
twitter_b
=
getTwitterSession
(
True
)
twitter_b
=
getTwitterSession
()
searchurl_v2
=
"https://twitter.com/i/api/graphql/nK1dw4oV3k4w5TdtcAdSww/SearchTimeline"
params_v2
=
{
"features"
:
json
.
dumps
({
...
...
@@ -146,6 +151,47 @@ def healthy():
# return {'healthy': True}
# return Response(status=500)
#return result
def
checkCookies
():
good
=
[]
bad
=
[]
for
cookie
in
cookies
:
print
(
"Checking cookie: "
+
cookie
,
file
=
sys
.
stderr
)
twitter_b
=
getTwitterSession
(
cookie
)
response
=
twitter_b
.
get
(
"https://api.twitter.com/1.1/guest/activate.json"
)
if
response
.
status_code
==
200
:
return
True
usertlurl
=
'https://twitter.com/i/api/graphql/oUZZZ8Oddwxs8Cd3iW3UEA/UserByScreenName'
screen_name
=
'Sena_n_Karin'
params
=
{
'variables'
:
json
.
dumps
({
'screen_name'
:
screen_name
,
'withSafetyModeUserFields'
:
True
,
}),
'features'
:
json
.
dumps
({
"hidden_profile_likes_enabled"
:
False
,
"responsive_web_graphql_exclude_directive_enabled"
:
True
,
"verified_phone_label_enabled"
:
False
,
"subscriptions_verification_info_verified_since_enabled"
:
True
,
"highlights_tweets_tab_ui_enabled"
:
True
,
"creator_subscriptions_tweet_preview_api_enabled"
:
True
,
"responsive_web_graphql_skip_user_profile_image_extensions_enabled"
:
False
,
"responsive_web_graphql_timeline_navigation_enabled"
:
True
})
}
usertl_b
=
twitter_b
.
get
(
usertlurl
,
params
=
params
)
usertl
=
usertl_b
usertl_json
=
usertl
.
json
()
if
usertl
.
status_code
==
200
or
not
(
"errors"
in
usertl_json
and
usertl_json
[
"errors"
][
0
][
"message"
]
==
"Could not authenticate you"
):
print
(
f
"Good cookie {usertl.status_code}: "
+
cookie
+
" "
+
usertl
.
text
,
file
=
sys
.
stderr
)
good
.
append
(
cookie
)
else
:
print
(
f
"Bad cookie {usertl.status_code}: "
+
cookie
+
" "
+
usertl
.
text
,
file
=
sys
.
stderr
)
bad
.
append
(
cookie
)
return
good
,
bad
@
app
.
route
(
"/<screen_name>"
)
...
...
@@ -180,7 +226,7 @@ def searchban(screen_name):
# twitter = OAuth1Session(TWITTER_IPHONE_CK, TWITTER_IPHONE_CS)
twitter_b
=
getTwitterSession
(
False
)
twitter_b
=
getTwitterSession
()
# check rate limit
# response = twitter_b.get("https://api.twitter.com/1.1/application/rate_limit_status.json")
...
...
@@ -504,4 +550,14 @@ def searchban(screen_name):
return
returnjson
if
__name__
==
'__main__'
:
app
.
run
(
debug
=
True
,
port
=
os
.
environ
.
get
(
"PORT"
,
5000
),
host
=
"0.0.0.0"
)
if
os
.
getenv
(
'CHECK_COOKIE'
):
good
,
bad
=
checkCookies
()
print
(
"Good cookies:"
)
for
g
in
good
:
print
(
g
)
print
(
"Bad cookies:"
)
for
b
in
bad
:
print
(
b
)
# quit
else
:
app
.
run
(
debug
=
True
,
port
=
os
.
environ
.
get
(
"PORT"
,
5000
),
host
=
"0.0.0.0"
)
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