feat: create File and MarkdownParser services
This commit is contained in:
		
							parent
							
								
									577812c493
								
							
						
					
					
						commit
						b11f5850fc
					
				
					 2 changed files with 33 additions and 0 deletions
				
			
		
							
								
								
									
										17
									
								
								src/services/file_service.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								src/services/file_service.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,17 @@ | ||||||
|  | import os | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class FileService: | ||||||
|  |     def __init__(self, eolas_file): | ||||||
|  |         self.eolas_file = eolas_file | ||||||
|  |         self.info = os.stat(eolas_file) | ||||||
|  | 
 | ||||||
|  |     def __extract_title(self): | ||||||
|  |         return os.path.basename(self.eolas_file) | ||||||
|  | 
 | ||||||
|  |     def get_info(self): | ||||||
|  |         return { | ||||||
|  |             "title": self.__extract_title(), | ||||||
|  |             "last_modified": self.info.st_mtime, | ||||||
|  |             "size": self.info.st_size, | ||||||
|  |         } | ||||||
							
								
								
									
										16
									
								
								src/services/markdown_parse_service.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/services/markdown_parse_service.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,16 @@ | ||||||
|  | import frontmatter | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class MarkdownParseService: | ||||||
|  |     """Extract tags, links and body text from Markdown entries""" | ||||||
|  | 
 | ||||||
|  |     def __init__(self, eolas_file): | ||||||
|  |         self.eolas_file = eolas_file | ||||||
|  | 
 | ||||||
|  |     def parse(self): | ||||||
|  |         with open(self.eolas_file) as f: | ||||||
|  |             metadata, content = frontmatter.parse(f.read()) | ||||||
|  |             return { | ||||||
|  |                 "tags": metadata.get("tags", []), | ||||||
|  |                 "body": content or "", | ||||||
|  |             } | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 thomasabishop
						thomasabishop