setScience(proj="ContentAnalysis", subProj="BlackListedArtists", subl=FALSE, load=FALSE)

f.in <- ingest.p("artist black list.txt")
blacklisted_artist_names <- readLines(f.in)

DT.blacklisted_artists_with_IDs <- get_artist_id_from_fuzzy_artist_name(blacklisted_artist_names)

DT.blacklisted_artists_with_IDs[, row_number := NULL]

## How many of each type of match do we have
DT.blacklisted_artists_with_IDs[, .N, by=match_type]

## How many times do we have each artist
DT.counts_per_artist <- DT.blacklisted_artists_with_IDs[match_type == "by_name", .N, by=artist_name]

## Write and send the data
writeDT(DT.blacklisted_artists_with_IDs, to=getRS())
writeDT(DT.counts_per_artist, to=getRS())

## write to snowflake, only the artistid, artist_name and artist_name_cleaned
DT.artists_blacklisted_by_itunes <- DT.blacklisted_artists_with_IDs[, list(artist_name, artist_name_cleaned), keyby=artistid]
DT.artists_blacklisted_by_itunes[, is_blacklisted_by_itunes := TRUE]
setSnowflake(wh="cron_jobs_small", start=TRUE)
ingestIntoSQL(DT=DT.artists_blacklisted_by_itunes, schema="bi", dbname="prod", wh="cron_jobs_small", datetime_type='TIMESTAMP_TZ', snowflake=TRUE)

if (FALSE) {
  sourceSupportFns(proj="Looker")
  create_lookml_from_tbl(dbname="prod", schema="bi", tbl="ARTISTS_BLACKLISTED_BY_ITUNES")
}

jesusForData()

