chore: tidy-up architecture
This commit is contained in:
		
							parent
							
								
									bd37e201e1
								
							
						
					
					
						commit
						b5954bf529
					
				
					 6 changed files with 45 additions and 50 deletions
				
			
		
							
								
								
									
										6
									
								
								setup.py
									
										
									
									
									
								
							
							
						
						
									
										6
									
								
								setup.py
									
										
									
									
									
								
							|  | @ -1,13 +1,11 @@ | ||||||
| from setuptools import setup, find_packages | from setuptools import find_packages, setup | ||||||
| 
 | 
 | ||||||
| setup( | setup( | ||||||
|     name="eolas-db", |     name="eolas-db", | ||||||
|     version="0.1", |     version="0.1", | ||||||
|     packages=find_packages(where="src"), |     packages=find_packages(where="src"), | ||||||
|     package_dir={"": "src"}, |     package_dir={"": "src"}, | ||||||
|     install_requires=[ |     install_requires=["python-frontmatter, "hurry.filesize"], | ||||||
|         # List your project dependencies here |  | ||||||
|     ], |  | ||||||
|     entry_points={ |     entry_points={ | ||||||
|         "console_scripts": [ |         "console_scripts": [ | ||||||
|             "run=app:main", |             "run=app:main", | ||||||
|  |  | ||||||
|  | @ -1,34 +1,10 @@ | ||||||
| from typing import List, TypedDict | from services.parse_file_service import ParseFileService | ||||||
| 
 |  | ||||||
| from services.file_service import FileService |  | ||||||
| from services.markdown_parse_service import MarkdownParseService |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| class Entry(TypedDict): |  | ||||||
|     title: str |  | ||||||
|     tags: List[str] |  | ||||||
|     body: str |  | ||||||
|     last_modified: int |  | ||||||
|     size: int |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Controller: | class Controller: | ||||||
|     def __init__(self): |     def __init__(self): | ||||||
|         pass |         pass | ||||||
| 
 | 
 | ||||||
|     def parse_entry(self, file_path) -> Entry: |     def parse_entry(self, file_path): | ||||||
|         markdown_parser_service = MarkdownParseService(file_path) |         parse_file_service = ParseFileService(file_path) | ||||||
|         file_parser_service = FileService(file_path) |         return parse_file_service.parse() | ||||||
| 
 |  | ||||||
|         markdown_metadata = markdown_parser_service.parse() |  | ||||||
|         file_data = file_parser_service.get_info() |  | ||||||
| 
 |  | ||||||
|         entry_metadata: Entry = { |  | ||||||
|             "title": file_data.get("title", ""), |  | ||||||
|             "last_modified": file_data.get("last_modified", 0), |  | ||||||
|             "size": file_data.get("size", 0), |  | ||||||
|             "tags": markdown_metadata.get("tags", []), |  | ||||||
|             "body": markdown_metadata.get("body", ""), |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         return entry_metadata |  | ||||||
|  |  | ||||||
							
								
								
									
										1
									
								
								src/scratch.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								src/scratch.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1 @@ | ||||||
|  | 
 | ||||||
|  | @ -1,17 +0,0 @@ | ||||||
| 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, |  | ||||||
|         } |  | ||||||
							
								
								
									
										37
									
								
								src/services/parse_file_service.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								src/services/parse_file_service.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,37 @@ | ||||||
|  | import os | ||||||
|  | from datetime import datetime | ||||||
|  | from typing import List, TypedDict | ||||||
|  | 
 | ||||||
|  | from hurry.filesize import size | ||||||
|  | 
 | ||||||
|  | from services.parse_markdown_service import ParseMarkdownService | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class Entry(TypedDict): | ||||||
|  |     title: str | ||||||
|  |     tags: List[str] | ||||||
|  |     body: str | ||||||
|  |     last_modified: str | ||||||
|  |     size: int | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class ParseFileService: | ||||||
|  |     def __init__(self, file): | ||||||
|  |         self.eolas_file = file | ||||||
|  |         self.info = os.stat(file) | ||||||
|  |         self.parse_markdown_service = ParseMarkdownService(file) | ||||||
|  | 
 | ||||||
|  |     def __get_title(self): | ||||||
|  |         return os.path.basename(self.eolas_file) | ||||||
|  | 
 | ||||||
|  |     def parse(self) -> Entry: | ||||||
|  |         markdown_data = self.parse_markdown_service.parse() | ||||||
|  |         return { | ||||||
|  |             "title": self.__get_title(), | ||||||
|  |             "last_modified": datetime.fromtimestamp(self.info.st_mtime).strftime( | ||||||
|  |                 "%Y-%m-%d %H:%M:%S" | ||||||
|  |             ), | ||||||
|  |             "size": size(self.info.st_size), | ||||||
|  |             "tags": markdown_data.get("tags", []), | ||||||
|  |             "body": markdown_data.get("body", []), | ||||||
|  |         } | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| import frontmatter | import frontmatter | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class MarkdownParseService: | class ParseMarkdownService: | ||||||
|     """Extract tags, links and body text from Markdown entries""" |     """Extract tags, links and body text from Markdown entries""" | ||||||
| 
 | 
 | ||||||
|     def __init__(self, eolas_file): |     def __init__(self, eolas_file): | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 thomasabishop
						thomasabishop