Skip to content

Commit

Permalink
CV2-3589 add language as a parameter for import_claim_reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
DGaffney committed Sep 13, 2023
1 parent 8a9a02b commit 4b11024
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 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,7 @@ 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|
Bot::Fetch.get_claim_reviews({ service: service_name, start_time: from2.strftime('%Y-%m-%d'), end_time: to2.strftime('%Y-%m-%d'), language: language}).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

0 comments on commit 4b11024

Please sign in to comment.