import csv
import requests

source = requests.get('https://thereportoftheweek-api.herokuapp.com/reports').json()

csv_file = open('hazecsv_new.csv', 'w')
csv_writer = csv.writer(csv_file)
csv_writer.writerow(['product', 'manufacturer', 'category', 'rating', 'rating_description'])

for data in source:
    if 'rating' in data:
        if data['rating'] >= 7:
            # print(data['rating'])
            if int(data['rating']) == 7:
                rating_description = 'Satisfactory'
            elif int(data['rating']) == 8:
                rating_description = 'Recommended'
            else:
                rating_description = 'Highly Commendable'
            csv_writer.writerow([data["product"], data["manufacturer"], data["category"], data["rating"], rating_description])