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
4c087348
Commit
4c087348
authored
Dec 14, 2020
by
Raphael Beer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix: mongo authentication
parent
29c7e3df
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
21 deletions
+19
-21
backend.py
backend.py
+12
-14
db.py
db.py
+7
-7
No files found.
backend.py
View file @
4c087348
...
...
@@ -13,7 +13,7 @@ import time
from
aiohttp
import
web
from
bs4
import
BeautifulSoup
from
db
import
connect
from
db
import
Database
from
statistics
import
count_sensitives
from
typeahead
import
test
as
test_typeahead
...
...
@@ -238,7 +238,7 @@ class TwitterSession:
self
.
overshot
=
0
# count the requests that failed because of rate limiting
if
self
.
remaining
is
0
:
if
self
.
remaining
==
0
:
log
(
'[rate-limit] Limit hit by '
+
str
(
self
.
username
)
+
'.'
)
self
.
overshot
+=
1
...
...
@@ -522,16 +522,6 @@ async def api(request):
else
:
return
web
.
json_response
(
result
)
async
def
login_accounts
(
accounts
,
cookie_dir
=
None
):
if
cookie_dir
is
not
None
and
not
os
.
path
.
isdir
(
cookie_dir
):
os
.
mkdir
(
cookie_dir
,
0o700
)
coroutines
=
[]
for
acc
in
accounts
:
session
=
TwitterSession
()
coroutines
.
append
(
session
.
login
(
*
acc
,
cookie_dir
=
cookie_dir
))
account_sessions
.
append
(
session
)
await
asyncio
.
gather
(
*
coroutines
)
async
def
login_guests
():
for
i
in
range
(
0
,
guest_session_pool_size
):
session
=
TwitterSession
()
...
...
@@ -555,6 +545,8 @@ parser.add_argument('--host', type=str, default='127.0.0.1', help='hostname/ip w
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
(
'--mongo-username'
,
type
=
str
,
default
=
''
,
help
=
'name of user in mongo database'
)
parser
.
add_argument
(
'--mongo-password'
,
type
=
str
,
default
=
''
,
help
=
'password for user in mongo database'
)
parser
.
add_argument
(
'--twitter-auth-key'
,
type
=
str
,
default
=
None
,
help
=
'auth key for twitter guest session'
,
required
=
True
)
parser
.
add_argument
(
'--cors-allow'
,
type
=
str
,
default
=
None
,
help
=
'value for Access-Control-Allow-Origin header'
)
args
=
parser
.
parse_args
()
...
...
@@ -585,9 +577,15 @@ if args.debug is not None:
def
run
():
global
db
db
=
connect
(
host
=
args
.
mongo_host
,
port
=
args
.
mongo_port
)
db
=
Database
(
host
=
args
.
mongo_host
,
port
=
args
.
mongo_port
,
username
=
args
.
mongo_username
,
password
=
args
.
mongo_password
,
db
=
args
.
mongo_db
)
loop
=
asyncio
.
get_event_loop
()
loop
.
run_until_complete
(
login_accounts
(
accounts
,
args
.
cookie_dir
))
#
loop.run_until_complete(login_accounts(accounts, args.cookie_dir))
loop
.
run_until_complete
(
login_guests
())
app
=
web
.
Application
()
app
.
add_routes
(
routes
)
...
...
db.py
View file @
4c087348
...
...
@@ -4,7 +4,7 @@ import sys
from
pymongo
import
MongoClient
,
errors
as
MongoErrors
,
DESCENDING
class
Database
:
def
__init__
(
self
,
host
=
None
,
port
=
27017
,
db
=
'tester'
):
def
__init__
(
self
,
host
=
None
,
port
=
27017
,
username
=
''
,
password
=
''
,
db
=
'tester'
):
# collection name definitions
RESULTS_COLLECTION
=
'results'
RATELIMIT_COLLECTION
=
'rate-limits'
...
...
@@ -13,7 +13,12 @@ class Database:
print
(
'[mongoDB] Connecting to '
+
host
+
':'
+
str
(
port
))
print
(
'[mongoDB] Using Database `'
+
db
+
'`'
)
# client and DB
self
.
client
=
MongoClient
(
host
,
port
,
serverSelectionTimeoutMS
=
3
)
self
.
client
=
MongoClient
(
host
=
host
,
port
=
port
,
username
=
username
,
password
=
password
,
serverSelectionTimeoutMS
=
3
)
self
.
db
=
self
.
client
[
db
]
# collections
...
...
@@ -41,8 +46,3 @@ class Database:
def
get_result_by_screen_name
(
self
,
screen_name
):
return
self
.
results
.
find_one
({
"profile.screen_name"
:
screen_name
},
sort
=
[(
"_id"
,
DESCENDING
)],
projection
=
{
"_id"
:
False
})
def
connect
(
host
=
None
,
port
=
27017
,
db
=
'tester'
):
if
host
is
None
:
raise
ValueError
(
'[mongoDB] Database constructor needs a `host`name or ip!'
)
return
Database
(
host
=
host
,
port
=
port
,
db
=
db
)
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