Ajout d'une pause possible par le navigateur
This commit is contained in:
parent
12e1f6dfb2
commit
a32d7217c9
@ -103,11 +103,15 @@ def run_recurrent_import(self, pk):
|
||||
importer = DBImporterEvents(self.request.id)
|
||||
|
||||
# prepare downloading and extracting processes
|
||||
downloader = (
|
||||
SimpleDownloader()
|
||||
if rimport.downloader == RecurrentImport.DOWNLOADER.SIMPLE
|
||||
else self.chromiumDownloader
|
||||
)
|
||||
if rimport.downloader == RecurrentImport.DOWNLOADER.SIMPLE:
|
||||
downloader = SimpleDownloader()
|
||||
elif rimport.downloader == RecurrentImport.DOWNLOADER.CHROMIUMHEADLESS:
|
||||
downloader = self.chromiumDownloader
|
||||
downloader.pause = False
|
||||
else:
|
||||
downloader = self.chromiumDownloader
|
||||
downloader.pause = True
|
||||
|
||||
if rimport.processor == RecurrentImport.PROCESSOR.ICAL:
|
||||
extractor = ICALExtractor()
|
||||
elif rimport.processor == RecurrentImport.PROCESSOR.ICALNOBUSY:
|
||||
|
@ -7,6 +7,7 @@ from selenium.webdriver.chrome.service import Service
|
||||
from selenium.webdriver.chrome.options import Options
|
||||
from selenium.common.exceptions import *
|
||||
from abc import ABC, abstractmethod
|
||||
import time
|
||||
|
||||
class Downloader(ABC):
|
||||
def __init__(self):
|
||||
@ -60,8 +61,9 @@ class SimpleDownloader(Downloader):
|
||||
|
||||
|
||||
class ChromiumHeadlessDownloader(Downloader):
|
||||
def __init__(self):
|
||||
def __init__(self, pause=True):
|
||||
super().__init__()
|
||||
self.pause = pause
|
||||
self.options = Options()
|
||||
self.options.add_argument("--headless=new")
|
||||
self.options.add_argument("--disable-dev-shm-usage")
|
||||
@ -88,6 +90,8 @@ class ChromiumHeadlessDownloader(Downloader):
|
||||
|
||||
try:
|
||||
self.driver.get(url)
|
||||
if self.pause:
|
||||
time.sleep(1)
|
||||
doc = self.driver.page_source
|
||||
|
||||
|
||||
|
@ -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'),
|
||||
),
|
||||
]
|
@ -1244,6 +1244,7 @@ class RecurrentImport(models.Model):
|
||||
class DOWNLOADER(models.TextChoices):
|
||||
SIMPLE = "simple", _("simple")
|
||||
CHROMIUMHEADLESS = "chromium headless", _("Headless Chromium")
|
||||
CHROMIUMHEADLESSPAUSE = "chromium (pause)", _("Headless Chromium (pause)")
|
||||
|
||||
class RECURRENCE(models.TextChoices):
|
||||
DAILY = (
|
||||
|
Loading…
Reference in New Issue
Block a user