- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
def check_web_property(file_folder_id)
folder_for_updated_files = FileFolder.find file_folder_id
# min_to_be_active = folder_for_updated_files.min_properties_to_be_active
process_uniq_id = SecureRandom.urlsafe_base64(30)
min_web_property = folder_for_updated_files.min_web_property_check
max_web_property = folder_for_updated_files.max_web_property_check
#puts "update ad_groups with given inventory limit to Previus Inventory = nil "
self.ad_groups.and( { "Inventory" => {'$gte' => folder_for_updated_files.min_web_property_check}}, {"Inventory" =>{'$lte' => folder_for_updated_files.max_web_property_check}}).update_all( "Previus Inventory" => nil, :update_complited => "no")
#PpcBuild.last.ad_groups.and( { "Previus Inventory" =>{'$gte' => 1}}, {"Previus Inventory" =>{'$lte' => 8 } }).count
puts "select ad_groups with given inventory limit"
selrcted_ad_groups = self.ad_groups.and( { "Inventory" =>{'$gte' => folder_for_updated_files.min_web_property_check}}, {"Inventory" =>{'$lte' => folder_for_updated_files.max_web_property_check } })
count_selected_ad_groups_for_processing = selrcted_ad_groups.count
selrcted_ad_groups.no_timeout.each do |ad|
if !self.uniq_urls.where("Landing Page"=> ad["Landing Page"], process_id: process_uniq_id).exists?
new_url = UniqUrl.new("Landing Page"=> ad["Landing Page"], process_id: process_uniq_id, ppc_build_id: self.id)
new_url.save
end
end
all_uniq_url_selected = self.uniq_urls.where(process_id: process_uniq_id)
elemetns_count = 0
all_uniq_url_selected.no_timeout.each do |uniq_url|
ad = AdGroup.find_by("Landing Page" => uniq_url["Landing Page"], ppc_build_id: self.id)
ad_parameters = { "Landing Page" => uniq_url["Landing Page"], ppc_build_id: self.id.to_s }
UpdateDataFromWebSite.perform_async(ad_parameters, process_uniq_id)
min_to_be_active = ad.min_for_ad_group_to_be_active
elemetns_count +=1
ad.web_update_inventory(ad.id.to_s, process_uniq_id, min_to_be_active)
if elemetns_count == 20
sleep 0
elemetns_count = 0
end
ad.update_attributes("Previus Inventory" => ad["Inventory"])
ad.push(process_id: process_id)
url = ad["Landing Page"]
uri = URI(url)
use_ssl = true
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = use_ssl
http.read_timeout = 20
http.open_timeout = 20
resp = http.start() { |http| http.get(uri.path) }
body = resp.body
page = Nokogiri::HTML(body)
if !page.css('.results-count').empty?
new_property = page.css('.results-count').first.text
property_number = new_property[/(?<=of\s)?\d{1,}\D?\d?{1,}/]
if property_number
ad.update_attributes("Inventory" => new_property.gsub(/\s+/, ' ')[/(?<=of\s)?\d{1,}\D?\d?{1,}/].strip)
else
ad.update_attributes("Inventory" => "0")
end
else
ad.update_attributes("Inventory" => "0")
end
ad.update_attributes("Status" => get_status(ad["Inventory"], min_to_be_active), update_complited: "yes")
end
питон DWORD