Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CV2-3589 add language as a parameter for import_claim_reviews #1652

Merged
merged 3 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions app/models/bot/fetch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def self.setup_service(installation, previous_services, new_services, language=n
end
end
previous_services.each { |previous_service| self.call_fetch_api(:delete, 'subscribe', { service: previous_service, url: self.webhook_url(team) }) }
Bot::Fetch::Import.delay_for(1.second, { queue: 'fetch', retry: 0 }).import_claim_reviews(installation.id) unless new_services.blank?
Bot::Fetch::Import.delay_for(1.second, { queue: 'fetch', retry: 0 }).import_claim_reviews(installation.id, language, false, nil) unless new_services.blank?
end

def self.is_service_supported?(service)
Expand Down Expand Up @@ -148,7 +148,7 @@ def self.call_fetch_api(verb, endpoint, params = {})
# Mandatory fields in the imported ClaimReview: claim_review_headline, claim_review_url, created_at and id

class Import
def self.import_claim_reviews(installation_id, force = false, maximum = nil)
def self.import_claim_reviews(installation_id, language = nil, force = false, maximum = nil)
installation = TeamBotInstallation.find(installation_id)
RequestStore.store[:skip_notifications] = true
RequestStore.store[:skip_cached_field_update] = false
Expand All @@ -171,7 +171,9 @@ def self.import_claim_reviews(installation_id, force = false, maximum = nil)
(from.to_i..to.to_i).step(step.days).each do |current_timestamp|
from2 = Time.at(current_timestamp)
to2 = from2 + step.days
Bot::Fetch.get_claim_reviews({ service: service_name, start_time: from2.strftime('%Y-%m-%d'), end_time: to2.strftime('%Y-%m-%d')}).each do |claim_review|
params = { service: service_name, start_time: from2.strftime('%Y-%m-%d'), end_time: to2.strftime('%Y-%m-%d'), language: language}
params[:language] = language if !language.nil?
Bot::Fetch.get_claim_reviews(params).each do |claim_review|
next if !maximum.nil? && total >= maximum
self.import_claim_review(claim_review, team.id, user.id, status_fallback, status_mapping, auto_publish_reports, force)
total += 1
Expand Down
5 changes: 3 additions & 2 deletions lib/tasks/data/fetch.rake
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ namespace :check do
services.each { |service| Bot::Fetch.call_fetch_api(:delete, 'subscribe', { service: service, url: Bot::Fetch.webhook_url(team) }) }
services.each { |service| Bot::Fetch.call_fetch_api(:post, 'subscribe', { service: service, url: Bot::Fetch.webhook_url(team) }) }
tbi = TeamBotInstallation.where(user_id: BotUser.find_by_login('fetch').id, team_id: team.id).last.id
Bot::Fetch::Import.delay(retry: 0).import_claim_reviews(tbi, force)
#dont support languages here, its just going to get too messy via the rake syntax.
Bot::Fetch::Import.delay(retry: 0).import_claim_reviews(tbi, nil, force)
end
end

Expand Down Expand Up @@ -172,7 +173,7 @@ namespace :check do
end
Bot::Fetch.set_service(team.slug, services, 'undetermined', status_mapping)
tbi = TeamBotInstallation.where(user_id: BotUser.find_by_login('fetch').id, team_id: team.id).last.id
Bot::Fetch::Import.import_claim_reviews(tbi, true, size)
Bot::Fetch::Import.import_claim_reviews(tbi, nil, true, size)
puts "A sample of #{size} articles were imported from Fetch service(s) #{services.join(', ')} to https://checkmedia.org/#{team.slug}/imported-fact-checks."
end
end
Expand Down
Loading