Skip to content

Instantly share code, notes, and snippets.

@swalke16
Last active December 6, 2018 18:08
Show Gist options
  • Save swalke16/da87a2e6c8c6d128c5d88559dd58307a to your computer and use it in GitHub Desktop.
Save swalke16/da87a2e6c8c6d128c5d88559dd58307a to your computer and use it in GitHub Desktop.
Add SNA Website Places to featured list
# Note this process is bad and currently broken. During this import I discovered that something like 92 records with google IDS matched during the populate step did not exist in our data pulled in by google. Furthermore we had dropped 19 other places that couldn't be matched to google.
#SCRAPE --> IMPORT —> POPULATE —>
web_list = PlaceList.find(51)
goog_list = PlaceList.find(45)
featured_list = FeaturedList.find(12)
PopulateGoogleIdsJob.perform_later(web_list)
missing = web_list.places.pluck(:google_id).compact - goog_list.places.pluck(:google_id)
web_goog_ids = web_list.places.pluck(:google_id).compact
# places that we couldn’t match to google (need moved to google list and added to featured)
no_match_ids = web_list.places.where(google_id: nil).pluck(:id)
Place.where(id: no_match_ids).each { |pl| pl.place_list = goog_list; pl.save! }
Place.where(id: no_match_ids).each { |pl| featured_list.places << pl }
# places that are on the web list but missing from google list (need moved to google list and added to featured)
missing_goog_list_ids = web_list.places.where(google_id: missing).pluck(:id)
Place.where(id: missing_goog_list_ids).each { |pl| pl.place_list = goog_list; pl.save! }
Place.where(id: missing_goog_list_ids).each { |pl| featured_list.places << pl }
# ids that matched from imported to current google list (just needs added to featured)
current_goog_list_ids = goog_list.places.where(google_id: web_goog_ids).pluck(:id)
Place.where(id: current_goog_list_ids).each { |pl| featured_list.places << pl rescue nil }
#Manual Categories…
no_cats = goog_list.places.select { |pl| pl.categories.empty? }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment