minor modifications

This commit is contained in:
doubaniux 2020-12-07 15:07:31 +01:00
parent b9bbb60fc7
commit 0e198653e8
2 changed files with 7 additions and 7 deletions

View file

@ -46,7 +46,7 @@ scraper_registry = {}
def log_url(func):
"""
Catch exceptions and log then pass the exceptions.
First postion argument of decorated function must be the url.
First postion argument (except cls/self) of decorated function must be the url.
"""
@functools.wraps(func)
def wrapper(*args, **kwargs):
@ -54,7 +54,7 @@ def log_url(func):
return func(*args, **kwargs)
except Exception as e:
# log the url
logger.error(f"Scrape Failed URL: {args[0]}")
logger.error(f"Scrape Failed URL: {args[1]}")
logger.error(str(e))
raise e
@ -102,10 +102,10 @@ class AbstractScraper:
@classmethod
def get_effective_url(cls, raw_url):
url = cls.regex.findall(raw_url)[0]
url = cls.regex.findall(raw_url)
if not url:
raise ValueError("not valid url")
return url
return url[0]
@classmethod
def download_page(cls, url, headers):

View file

@ -4,7 +4,7 @@ import random
import functools
from django.core.exceptions import ObjectDoesNotExist
from boofilsic.settings import MASTODON_TIMEOUT
from boofilsic.settings import CLIENT_NAME, APP_WEBSITE
from boofilsic.settings import CLIENT_NAME, APP_WEBSITE, REDIRECT_URIS
from .models import CrossSiteUserInfo
# See https://docs.joinmastodon.org/methods/accounts/
@ -98,13 +98,13 @@ def create_app(domain_name):
payload = {
'client_name': CLIENT_NAME,
'scopes': 'read write follow',
'redirect_uris': f'{APP_WEBSITE}/users/OAuth2_login/',
'redirect_uris': REDIRECT_URIS,
'website': APP_WEBSITE
}
from boofilsic.settings import DEBUG
if DEBUG:
payload['redirect_uris'] = 'http://localhost/users/OAuth2_login/'
payload['redirect_uris'] = 'http://localhost/users/OAuth2_login/\nurn:ietf:wg:oauth:2.0:oob'
response = post(url, data=payload)
return response