import csv


def read_cika_info():
    all_cika_title = {}
    cika_file = open("soyoung_service_cika.csv", "r", encoding="utf-8")
    for item in cika_file.readlines():
        cika = eval(item)
        for key, values in cika.items():
            all_cika_title[key] = values

    print(all_cika_title)
    cika_file.close()
    return all_cika_title


def np_write_csv_data():
    all_cika_title = read_cika_info()
    write_file = open("soyoung_service_write_cika.csv", "a+", encoding="utf-8")
    # /Users/edz/Desktop/xinyang.csv
    with open("soyoung_service.csv", encoding='utf-8') as f:
        reader = csv.reader(f)
        header_row = next(reader)
        print(header_row)
        for row in reader:
            service_id = row[2]
            cika_info = all_cika_title.get(service_id)
            if cika_info:
                print('cika_info:', cika_info)
                write_file.write(str(row.append(cika_info)))
                write_file.write("\n")
    write_file.close()


if __name__ == '__main__':
    np_write_csv_data()
