Skip to content

Commit bfa6afa

Browse files
committed
Refactoring and linting, added notifications about frequent search errors
1 parent bfaf276 commit bfa6afa

20 files changed

+1351
-787
lines changed

format.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
FILES="maigret wizard.py maigret.py"
3+
4+
echo 'black'
5+
black --skip-string-normalization $FILES

lint.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
FILES="maigret wizard.py maigret.py"
3+
4+
echo 'syntax errors or undefined names'
5+
flake8 --count --select=E9,F63,F7,F82 --show-source --statistics $FILES
6+
7+
echo 'warning'
8+
flake8 --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --ignore=E731,W503 $FILES
9+
10+
echo 'mypy'
11+
mypy ./maigret

maigret.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ def run():
1515

1616

1717
if __name__ == "__main__":
18-
run()
18+
run()

maigret/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
from .checking import maigret as search
44
from .sites import MaigretEngine, MaigretSite, MaigretDatabase
5-
from .notify import QueryNotifyPrint as Notifier
5+
from .notify import QueryNotifyPrint as Notifier

maigret/activation.py

+25-23
Original file line numberDiff line numberDiff line change
@@ -9,46 +9,48 @@ class ParsingActivator:
99
@staticmethod
1010
def twitter(site, logger, cookies={}):
1111
headers = dict(site.headers)
12-
del headers['x-guest-token']
13-
r = requests.post(site.activation['url'], headers=headers)
12+
del headers["x-guest-token"]
13+
r = requests.post(site.activation["url"], headers=headers)
1414
logger.info(r)
1515
j = r.json()
16-
guest_token = j[site.activation['src']]
17-
site.headers['x-guest-token'] = guest_token
16+
guest_token = j[site.activation["src"]]
17+
site.headers["x-guest-token"] = guest_token
1818

1919
@staticmethod
2020
def vimeo(site, logger, cookies={}):
2121
headers = dict(site.headers)
22-
if 'Authorization' in headers:
23-
del headers['Authorization']
24-
r = requests.get(site.activation['url'], headers=headers)
25-
jwt_token = r.json()['jwt']
26-
site.headers['Authorization'] = 'jwt ' + jwt_token
22+
if "Authorization" in headers:
23+
del headers["Authorization"]
24+
r = requests.get(site.activation["url"], headers=headers)
25+
jwt_token = r.json()["jwt"]
26+
site.headers["Authorization"] = "jwt " + jwt_token
2727

2828
@staticmethod
2929
def spotify(site, logger, cookies={}):
3030
headers = dict(site.headers)
31-
if 'Authorization' in headers:
32-
del headers['Authorization']
33-
r = requests.get(site.activation['url'])
34-
bearer_token = r.json()['accessToken']
35-
site.headers['authorization'] = f'Bearer {bearer_token}'
31+
if "Authorization" in headers:
32+
del headers["Authorization"]
33+
r = requests.get(site.activation["url"])
34+
bearer_token = r.json()["accessToken"]
35+
site.headers["authorization"] = f"Bearer {bearer_token}"
3636

3737
@staticmethod
3838
def xssis(site, logger, cookies={}):
3939
if not cookies:
40-
logger.debug('You must have cookies to activate xss.is parsing!')
40+
logger.debug("You must have cookies to activate xss.is parsing!")
4141
return
4242

4343
headers = dict(site.headers)
4444
post_data = {
45-
'_xfResponseType': 'json',
46-
'_xfToken': '1611177919,a2710362e45dad9aa1da381e21941a38'
45+
"_xfResponseType": "json",
46+
"_xfToken": "1611177919,a2710362e45dad9aa1da381e21941a38",
4747
}
48-
headers['content-type'] = 'application/x-www-form-urlencoded; charset=UTF-8'
49-
r = requests.post(site.activation['url'], headers=headers, cookies=cookies, data=post_data)
50-
csrf = r.json()['csrf']
51-
site.get_params['_xfToken'] = csrf
48+
headers["content-type"] = "application/x-www-form-urlencoded; charset=UTF-8"
49+
r = requests.post(
50+
site.activation["url"], headers=headers, cookies=cookies, data=post_data
51+
)
52+
csrf = r.json()["csrf"]
53+
site.get_params["_xfToken"] = csrf
5254

5355

5456
async def import_aiohttp_cookies(cookiestxt_filename):
@@ -62,8 +64,8 @@ async def import_aiohttp_cookies(cookiestxt_filename):
6264
for key, cookie in list(domain.values())[0].items():
6365
c = Morsel()
6466
c.set(key, cookie.value, cookie.value)
65-
c['domain'] = cookie.domain
66-
c['path'] = cookie.path
67+
c["domain"] = cookie.domain
68+
c["path"] = cookie.path
6769
cookies_list.append((key, c))
6870

6971
cookies.update_cookies(cookies_list)

0 commit comments

Comments
 (0)