Add check to ensure export directory exists
This commit is contained in:
		
							parent
							
								
									d5081f6cd8
								
							
						
					
					
						commit
						ce7c2102a1
					
				
					 2 changed files with 7 additions and 1 deletions
				
			
		
							
								
								
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue