From 8adae2f9f5fe9d2ecf3c9cf61c98905de2ead8d4 Mon Sep 17 00:00:00 2001 From: mahdi lamriben Date: Fri, 29 Nov 2024 18:33:59 +0100 Subject: [PATCH] fix filter --- datasources/connectors/open_agenda.rb | 29 +++++++++++++++------------ datasources/sources/open_agenda.rb | 2 +- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/datasources/connectors/open_agenda.rb b/datasources/connectors/open_agenda.rb index ca695be..d221f36 100644 --- a/datasources/connectors/open_agenda.rb +++ b/datasources/connectors/open_agenda.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true # typed: true +require 'async' require 'sorbet-runtime' require_relative 'connector' @@ -19,7 +20,6 @@ def setup(kiba) })) agenda_uid = @settings['agenda_uid'].to_s - print(agenda_uid) if agenda_uid.empty? agendas = OpenAgendaSource.fetch('agendas', { key: @settings['key'] @@ -36,20 +36,23 @@ def setup(kiba) def _call(kiba, agenda_uid) @settings['agenda_uid'] = agenda_uid events = OpenAgendaSource.fetch("agendas/#{agenda_uid}/events", { - key: @settings['key'] + key: @settings['key'], + 'timings[gte]' => Date.today, }) - events.each do |event| - destination_id = "#{agenda_uid}-#{event['uid']}-#{event['title']['fr']}" - name = event['title'] + events.map do |event| + Async do + destination_id = "#{agenda_uid}-#{event['uid']}-#{event['title']['fr']}" + name = event['title'] - kiba.source( - OpenAgendaSource, - @job_id, - destination_id, - name, - OpenAgendaSource::Settings.from_hash(@settings.merge({ 'event_uid' => event['uid'].to_s, 'agenda_uid' => agenda_uid })), - ) - end + kiba.source( + OpenAgendaSource, + @job_id, + destination_id, + name, + OpenAgendaSource::Settings.from_hash(@settings.merge({ 'event_uid' => event['uid'].to_s, 'agenda_uid' => agenda_uid })), + ) + end + end.each(&:wait) end end diff --git a/datasources/sources/open_agenda.rb b/datasources/sources/open_agenda.rb index 4e5de55..9dc677b 100644 --- a/datasources/sources/open_agenda.rb +++ b/datasources/sources/open_agenda.rb @@ -87,7 +87,7 @@ def self.fetch(path, query, key = 'events', size = 100, **kwargs) end def self.fetch_event(path, query) - url = T.let(build_url(path, query.merge({ 'timings[gte]' => Date.today })), T.nilable(String)) + url = T.let(build_url(path, query), T.nilable(String)) response = HTTP.follow.get(url) raise [url, response].inspect unless response.status.success?