Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- desc "Inserts all the link data from the link building spreadsheet in Google Drive"
- task :fetch_actual_links => :environment do
- Client.all.each do |client|
- worksheet = GoogleDriveAPI.get_link_worksheet(client.client_name)
- puts "checking for new links for " + client.client_name
- # A worksheet for this client was found
- if(worksheet != nil)
- (14..worksheet.num_rows).each do |i|
- # Read the data from the columns
- link_directory_url = worksheet[i, 1].downcase
- listing_url = worksheet[i, 3]
- status = worksheet[i, 5]
- submission_date = worksheet[i, 6]
- # Fetch the correct link directory to attach this actual link to
- # If the link directory does not exist - create it
- if(LinkDirectory.where("url = ?", link_directory_url).blank?)
- puts link_directory_url + " does not exist in the db, adding it..."
- LinkDirectory.create(url: link_directory_url)
- link_directory = LinkDirectory.where("url = ?", link_directory_url).first
- else
- puts link_directory_url + " already exists in the db"
- link_directory = LinkDirectory.where("url = ?", link_directory_url).first
- end
- # If the link does not already exist - create it
- if(ActualLink.where("link_directory_id = ? AND client_id = ?", link_directory.id, client.id).count == 0 && status != '')
- puts "creating a link..."
- ActualLink.create(link_directory_id: link_directory.id, client_id: client.id, status: status, listing_url: listing_url)
- elsif(ActualLink.where("link_directory_id = ? AND client_id = ?", link_directory.id, client.id).count > 0 && status != '')
- actual_link = ActualLink.where("link_directory_id = ? AND client_id = ?", link_directory.id, client.id).first
- actual_link.status = status
- actual_link.save
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement