mirror of
https://github.com/JimmXinu/FanFicFare.git
synced 2025-12-06 17:02:43 +01:00
Clean up cloudscraper import
This commit is contained in:
parent
d652b4a9fe
commit
d33decd8f5
1 changed files with 9 additions and 18 deletions
|
|
@ -37,23 +37,15 @@ from .six import text_type as unicode
|
||||||
from .six import string_types as basestring
|
from .six import string_types as basestring
|
||||||
from .six import ensure_binary, ensure_text
|
from .six import ensure_binary, ensure_text
|
||||||
|
|
||||||
try:
|
|
||||||
## make sure to fail if not in calibre plugin.
|
|
||||||
from calibre_plugins.fanficfare_plugin.fanficfare import adapters
|
|
||||||
## isn't found in plugin when only imported down below inside
|
|
||||||
## get_scraper() Need to do something more elegant. XXX
|
|
||||||
import cloudscraper
|
|
||||||
## and get_resources() does work down inside
|
|
||||||
## cloudscraper.user_agent.__init__.py No idea why not.
|
|
||||||
cloudscraper.user_agent.browsers_json = ensure_text(get_resources('cloudscraper/user_agent/browsers.json'))
|
|
||||||
except ImportError:
|
|
||||||
pass # cloudscraper from pip installed version
|
|
||||||
|
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
import pickle
|
import pickle
|
||||||
|
|
||||||
|
## isn't found in plugin when only imported down below inside
|
||||||
|
## get_scraper()
|
||||||
|
import cloudscraper
|
||||||
|
|
||||||
from . import exceptions
|
from . import exceptions
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
@ -1081,12 +1073,11 @@ class Configuration(ConfigParser):
|
||||||
|
|
||||||
def get_scraper(self):
|
def get_scraper(self):
|
||||||
if not self.scraper:
|
if not self.scraper:
|
||||||
if True: # just for testing requests w/o added complexity of cloudscraper
|
|
||||||
import cloudscraper
|
|
||||||
self.scraper = cloudscraper.CloudScraper()
|
self.scraper = cloudscraper.CloudScraper()
|
||||||
else:
|
## CloudScraper is subclass of requests.Session.
|
||||||
import requests
|
## probably need import higher up if ever used.
|
||||||
self.scraper = requests.Session()
|
# import requests
|
||||||
|
# self.scraper = requests.Session()
|
||||||
self.scraper.cookies = self.cookiejar
|
self.scraper.cookies = self.cookiejar
|
||||||
return self.scraper
|
return self.scraper
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue