On améliore la gestion du debug
This commit is contained in:
parent
34ac57f35f
commit
9475c99e0f
@ -52,7 +52,7 @@ class CExtractor(TwoStepsExtractor):
|
||||
def build_event_url_list(self, content):
|
||||
soup = BeautifulSoup(content, "html.parser")
|
||||
|
||||
debug = False
|
||||
debug = True
|
||||
|
||||
self.found = False
|
||||
links = soup.find_all("a")
|
||||
@ -65,22 +65,24 @@ class CExtractor(TwoStepsExtractor):
|
||||
self.has_page_items = False
|
||||
self.find_in_js(soup)
|
||||
|
||||
|
||||
if not self.found:
|
||||
logger.warning("cannot find any event link in events page. Save content page")
|
||||
if debug:
|
||||
CExtractor.dump_content_for_debug(content, self.url)
|
||||
|
||||
if not self.has_page_items:
|
||||
raise Exception(_("the page was not yet populated with events, so the loading time was probably too short"))
|
||||
|
||||
if not self.found and debug:
|
||||
logger.warning("cannot find any event link in events page. Save content page in " + filename)
|
||||
self.dump_content_for_debug(content)
|
||||
|
||||
|
||||
def dump_content_for_debug(self, content):
|
||||
def dump_content_for_debug(content, url):
|
||||
directory = "errors/"
|
||||
if not os.path.exists(directory):
|
||||
os.makedirs(directory)
|
||||
now = datetime.now()
|
||||
filename = directory + now.strftime("%Y%m%d_%H%M%S") + ".html"
|
||||
with open(filename, "w") as text_file:
|
||||
text_file.write("<!-- " + self.url + " -->\n\n")
|
||||
text_file.write("<!-- " + url + " -->\n\n")
|
||||
text_file.write(content)
|
||||
|
||||
|
||||
@ -111,7 +113,8 @@ class CExtractor(TwoStepsExtractor):
|
||||
|
||||
self.add_event(default_values, **event)
|
||||
else:
|
||||
self.dump_content_for_debug(event_content)
|
||||
if debug:
|
||||
CExtractor.dump_content_for_debug(event_content, event_url)
|
||||
raise Exception(
|
||||
_("Cannot get Facebook event from {}").format(event_url)
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user