Ajout d'une pause possible par le navigateur

This commit is contained in:
Jean-Marie Favreau 2024-08-29 01:39:36 +02:00
parent 12e1f6dfb2
commit a32d7217c9
4 changed files with 33 additions and 6 deletions

View File

@ -103,11 +103,15 @@ def run_recurrent_import(self, pk):
importer = DBImporterEvents(self.request.id) importer = DBImporterEvents(self.request.id)
# prepare downloading and extracting processes # prepare downloading and extracting processes
downloader = ( if rimport.downloader == RecurrentImport.DOWNLOADER.SIMPLE:
SimpleDownloader() downloader = SimpleDownloader()
if rimport.downloader == RecurrentImport.DOWNLOADER.SIMPLE elif rimport.downloader == RecurrentImport.DOWNLOADER.CHROMIUMHEADLESS:
else self.chromiumDownloader downloader = self.chromiumDownloader
) downloader.pause = False
else:
downloader = self.chromiumDownloader
downloader.pause = True
if rimport.processor == RecurrentImport.PROCESSOR.ICAL: if rimport.processor == RecurrentImport.PROCESSOR.ICAL:
extractor = ICALExtractor() extractor = ICALExtractor()
elif rimport.processor == RecurrentImport.PROCESSOR.ICALNOBUSY: elif rimport.processor == RecurrentImport.PROCESSOR.ICALNOBUSY:

View File

@ -7,6 +7,7 @@ from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import * from selenium.common.exceptions import *
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
import time
class Downloader(ABC): class Downloader(ABC):
def __init__(self): def __init__(self):
@ -60,8 +61,9 @@ class SimpleDownloader(Downloader):
class ChromiumHeadlessDownloader(Downloader): class ChromiumHeadlessDownloader(Downloader):
def __init__(self): def __init__(self, pause=True):
super().__init__() super().__init__()
self.pause = pause
self.options = Options() self.options = Options()
self.options.add_argument("--headless=new") self.options.add_argument("--headless=new")
self.options.add_argument("--disable-dev-shm-usage") self.options.add_argument("--disable-dev-shm-usage")
@ -88,6 +90,8 @@ class ChromiumHeadlessDownloader(Downloader):
try: try:
self.driver.get(url) self.driver.get(url)
if self.pause:
time.sleep(1)
doc = self.driver.page_source doc = self.driver.page_source

View File

@ -0,0 +1,18 @@
# Generated by Django 4.2.7 on 2024-08-28 23:34
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('agenda_culturel', '0068_alter_recurrentimport_processor'),
]
operations = [
migrations.AlterField(
model_name='recurrentimport',
name='downloader',
field=models.CharField(choices=[('simple', 'simple'), ('chromium headless', 'Headless Chromium'), ('chromium (pause)', 'Headless Chromium (pause)')], default='simple', max_length=20, verbose_name='Downloader'),
),
]

View File

@ -1244,6 +1244,7 @@ class RecurrentImport(models.Model):
class DOWNLOADER(models.TextChoices): class DOWNLOADER(models.TextChoices):
SIMPLE = "simple", _("simple") SIMPLE = "simple", _("simple")
CHROMIUMHEADLESS = "chromium headless", _("Headless Chromium") CHROMIUMHEADLESS = "chromium headless", _("Headless Chromium")
CHROMIUMHEADLESSPAUSE = "chromium (pause)", _("Headless Chromium (pause)")
class RECURRENCE(models.TextChoices): class RECURRENCE(models.TextChoices):
DAILY = ( DAILY = (