66 Generates the unmatched lines in compressed csv format according to sales which matches with 'accounting_date' field
69 date (str): accounting_date, i.e processing files date
70 Returns (str): Nothing.
73 bucket = event[
"bucket"]
75 s3_path =
"{}/unmatched_lines/{}/".format(event[
"path"], date)
77 filename = f
"unmatched_lines_{file}.csv"
78 print(f
"Creating {filename}")
79 date = datetime.strptime(date,
"%Y-%m-%d")
80 csv_columns = [
"file",
"line",
"release_id",
"isrc_id",
"release_title",
"track_title",
"artists",
"label_id",
"service_id"]
83 with open(path+filename,
'w', encoding=
'utf-8')
as csvfile:
84 writer = csv.DictWriter(csvfile, fieldnames=csv_columns)
86 fields = {
"_id":0,
"file": 1,
"line": 1,
"release_id": 1,
"isrc_id": 1,
"release_title": 1,
"track_title": 1,
"artists": 1,
"label_id": 1,
"service_id": 1}
87 template_sales = collection.find({
"accounting_date": {
"$in": [date]},
"client_id": event[
"client_id"],
"clean": 0},fields)
88 for post
in template_sales:
93 print(
"Compressing file")
94 if os.path.isfile(f
"{path+filename}.gz"):
95 os.system(
"rm {}.gz".format(path+filename))
96 command = f
"gzip {path+filename}"
98 filename = filename+
".gz"
99 print(f
"{filename} is ready!")
100 url_to_download, final_path = upload_files_s3(bucket, s3_path, path, filename)
101 print(send_unmatched_report(event[
"client_email"], file, url_to_download, lines, num_files))
102 os.system(
"rm -r {}".format(path+filename))
103 except Exception
as e:
104 print(sys.exc_info()[2])
105 print(traceback.format_exc())