diff --git a/.gitignore b/.gitignore index 39d6292..46008f8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ # Edit at https://www.toptal.com/developers/gitignore?templates=python,pycharm urls.txt +export/ ### PyCharm ### # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider diff --git a/csv_exporter.py b/csv_exporter.py index 4419e50..737e870 100644 --- a/csv_exporter.py +++ b/csv_exporter.py @@ -1,6 +1,9 @@ +import os.path + from tripadvisor_attraction import TripadvisorAttraction, TripadvisorReview TABLE_HEADING = "username^review_title^review_text^posting_date^count_stars^count_likes^translated_by" +EXPORT_DIRECTORY = 'export' def export_attraction(attraction: TripadvisorAttraction): @@ -8,7 +11,9 @@ def export_attraction(attraction: TripadvisorAttraction): for review in attraction.reviews: export_string += line_for_review(review) + '\n' - with open(f'export/{attraction.title} ({attraction.count_of_reviews}).csv', 'w') as export_file: + if not os.path.isdir(EXPORT_DIRECTORY): + os.makedirs(EXPORT_DIRECTORY) + with open(f'{EXPORT_DIRECTORY}/{attraction.title} ({attraction.count_of_reviews}).csv', 'w') as export_file: export_file.writelines(export_string)