setScience("Discover_Weekly", subProj="UserCounts")
setGitBranchToSystem(); .g()

sourceSupportFns(proj="Looker")

wh <- "SpotifyAggregates"
dbname <- "prod"

setSnowflake(wh=wh, dbname=dbname, start=TRUE)


tables_main <- {
  list(
  spot_stream_counts = 
  c(
    "by_main_isrc"
  , "by_main_isrc_source_playlist"
  , "by_main_isrc_source"
  , "by_main_isrc_country_code"
  , "by_main_isrc_country_code_source_playlist"
  , "BY_main_isrc_4wks"
  ))
}

tables_main[["spot_user_counts"]] <- removeText("main_", tables_main[["spot_stream_counts"]])

schemas <- c("spot_stream_counts", "spot_user_counts")


lapply(schemas, function(schema) create_lookml_model_from_schema(schema=schema, wh=wh, dbname=dbname, only_include_these_tbls = tables_main[[schema]]) )


##  If there are other files there that I do not want to copy, use this
##
#  ## When moving them over;  
#  schema <- schemas[[1]]
#  files <- dir(as.path('~rsaporta/git/orch/out/Discover_Weekly/auto_generated_lookmls/', schema), full=TRUE)
#  files_to_copy <- fileInfo(files)[(as.Date(mtime) == today()), file]
#  
#  
#  file.copy(from=files_to_copy, to='/Users/rsaporta/development/looks/')
#  
#  lapply(schemas, function(schema) {
#    basename(files) %>% removeText(sprintf("(^(bi|%s)\\.|\\.view.lookml$) schema, .) %>% removeText("", .)
#  } )