-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_utils.py
27 lines (22 loc) · 989 Bytes
/
file_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import csv
import os
def dir_check(MAIN_DIR_PATH, MONTH_DIR_PATH):
# this function checks the existance of directories
if not os.path.exists(MAIN_DIR_PATH):
os.mkdir(MAIN_DIR_PATH)
if not os.path.exists(MAIN_DIR_PATH+MONTH_DIR_PATH):
os.mkdir(MAIN_DIR_PATH+MONTH_DIR_PATH)
def create_csv(PATH, divisions, links, streams): # opening the csv output file
with open(PATH, "w") as file:
headers = ['Song', 'Artist', 'Download', 'View']
# setting the headers of the file
csv_writer = csv.DictWriter(file, fieldnames=headers)
csv_writer.writeheader()
for i in range(0, len(divisions)): # a loop for managing the data
division, link, stream = divisions[i], links[i], streams[i]
csv_writer.writerow({
'Song': division.strong.text,
'Artist': division.span.text[3:],
'Download': link.a["href"],
'View': stream.text
})