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
ab88423f
Commit
ab88423f
authored
Sep 03, 2019
by
Raphael Beer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor: read guestkey from .env
parent
d39eb567
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
7 deletions
+11
-7
.env.example
.env.example
+1
-0
backend.py
backend.py
+8
-6
run.sh
run.sh
+2
-1
No files found.
.env.example
View file @
ab88423f
...
...
@@ -8,3 +8,4 @@ MONGO_PORT=27017
MONGO_DB=tester
MONGO_RESULTS_COLLECTION=results
MONGO_OVERSHOT_COLLECTION=overshot
TWITTER_AUTH_KEY=GRAPHQL_KEY
backend.py
View file @
ab88423f
...
...
@@ -13,8 +13,6 @@ from aiohttp import web
from
bs4
import
BeautifulSoup
from
db
import
connect
twitter_auth_key
=
"AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs
%3
D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA"
routes
=
web
.
RouteTableDef
()
class
UnexpectedApiError
(
Exception
):
...
...
@@ -53,6 +51,8 @@ def next_session():
class
TwitterSession
:
_user_url
=
"https://api.twitter.com/graphql/SEn6Mq-OakvVOT1CJqUO2A/UserByScreenName?variables="
twitter_auth_key
=
None
def
__init__
(
self
):
self
.
_headers
=
{
"User-Agent"
:
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36"
...
...
@@ -83,7 +83,7 @@ class TwitterSession:
self
.
_headers
[
'X-Csrf-Token'
]
=
cookie
.
value
async
def
get_guest_token
(
self
):
self
.
_headers
[
'Authorization'
]
=
'Bearer '
+
twitter_auth_key
self
.
_headers
[
'Authorization'
]
=
'Bearer '
+
self
.
twitter_auth_key
async
with
self
.
_session
.
post
(
"https://api.twitter.com/1.1/guest/activate.json"
,
headers
=
self
.
_headers
)
as
r
:
response
=
await
r
.
json
()
guest_token
=
response
.
get
(
"guest_token"
,
None
)
...
...
@@ -155,7 +155,7 @@ class TwitterSession:
else
:
async
with
self
.
_session
.
get
(
'https://twitter.com'
,
headers
=
self
.
_headers
)
as
r
:
await
r
.
text
()
self
.
set_csrf_header
()
self
.
username
=
username
...
...
@@ -165,7 +165,7 @@ class TwitterSession:
else
:
await
self
.
login_guest
()
self
.
_headers
[
'Authorization'
]
=
'Bearer '
+
twitter_auth_key
self
.
_headers
[
'Authorization'
]
=
'Bearer '
+
self
.
twitter_auth_key
async
def
get
(
self
,
url
,
retries
=
0
):
self
.
set_csrf_header
()
...
...
@@ -326,7 +326,7 @@ class TwitterSession:
reference_session
=
next_session
()
if
reference_session
is
None
:
return
global
account_index
account_index
+=
1
...
...
@@ -534,8 +534,10 @@ parser.add_argument('--port', type=int, default=8080, help='port which to listen
parser
.
add_argument
(
'--mongo-host'
,
type
=
str
,
default
=
'localhost'
,
help
=
'hostname or IP of mongoDB service to connect to'
)
parser
.
add_argument
(
'--mongo-port'
,
type
=
int
,
default
=
27017
,
help
=
'port of mongoDB service to connect to'
)
parser
.
add_argument
(
'--mongo-db'
,
type
=
str
,
default
=
'tester'
,
help
=
'name of mongo database to use'
)
parser
.
add_argument
(
'--twitter-auth-key'
,
type
=
str
,
default
=
None
,
help
=
'auth key for twitter guest session'
,
required
=
True
)
args
=
parser
.
parse_args
()
TwitterSession
.
twitter_auth_key
=
args
.
twitter_auth_key
;
ensure_dir
(
args
.
cookie_dir
)
with
open
(
args
.
account_file
,
"r"
)
as
f
:
...
...
run.sh
View file @
ab88423f
...
...
@@ -23,4 +23,5 @@ python3 ./backend.py \
--port
"
$PORT
"
\
--mongo-host
$MONGO_HOST
\
--mongo-port
$MONGO_PORT
\
--mongo-db
$MONGO_DB
--mongo-db
$MONGO_DB
\
--twitter-auth-key
$TWITTER_AUTH_KEY
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