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
9d137208
Commit
9d137208
authored
Feb 17, 2020
by
Raphael Beer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor: typeahead (search suggestions) test into own module
parent
bfee6a3a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
9 deletions
+14
-9
backend.py
backend.py
+3
-9
typeahead.py
typeahead.py
+11
-0
No files found.
backend.py
View file @
9d137208
...
...
@@ -14,6 +14,8 @@ from aiohttp import web
from
bs4
import
BeautifulSoup
from
db
import
connect
from
typeahead
import
test
as
test_typeahead
routes
=
web
.
RouteTableDef
()
class
UnexpectedApiError
(
Exception
):
...
...
@@ -202,9 +204,6 @@ class TwitterSession:
additional_query
=
"&tweet_search_mode=live"
return
await
self
.
get
(
"https://api.twitter.com/2/search/adaptive.json?q="
+
urllib
.
parse
.
quote
(
query
)
+
"&count=20&spelling_corrections=0"
+
additional_query
)
async
def
typeahead_raw
(
self
,
query
):
return
await
self
.
get
(
"https://api.twitter.com/1.1/search/typeahead.json?src=search_box&result_type=users&q="
+
urllib
.
parse
.
quote
(
query
))
async
def
profile_raw
(
self
,
username
):
return
await
self
.
get
(
"https://api.twitter.com/1.1/users/show.json?screen_name="
+
urllib
.
parse
.
quote
(
username
))
...
...
@@ -436,12 +435,7 @@ class TwitterSession:
except
(
KeyError
,
IndexError
):
pass
typeahead_raw
=
await
self
.
typeahead_raw
(
"@"
+
username
)
result
[
"tests"
][
"typeahead"
]
=
False
try
:
result
[
"tests"
][
"typeahead"
]
=
len
([
1
for
user
in
typeahead_raw
[
"users"
]
if
user
[
"screen_name"
]
.
lower
()
==
username
.
lower
()])
>
0
except
KeyError
:
pass
result
[
"tests"
][
"typeahead"
]
=
await
test_typeahead
(
self
,
username
)
if
"search"
in
result
[
"tests"
]
and
result
[
"tests"
][
"search"
]
==
False
:
result
[
"tests"
][
"ghost"
]
=
await
self
.
test_ghost_ban
(
user_id
)
...
...
typeahead.py
0 → 100644
View file @
9d137208
import
urllib.parse
async
def
test
(
session
,
screen_name
):
query
=
"@"
+
screen_name
suggestions
=
await
session
.
get
(
"https://api.twitter.com/1.1/search/typeahead.json?src=search_box&result_type=users&q="
+
urllib
.
parse
.
quote
(
query
))
try
:
result
=
len
([
1
for
user
in
suggestions
[
"users"
]
if
user
[
"screen_name"
]
.
lower
()
==
screen_name
.
lower
()])
>
0
except
:
result
=
False
return
result
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