Add basic parser for obsidian notes
This commit is contained in:
parent
b3b18df868
commit
0d7ce9135c
6 changed files with 159 additions and 0 deletions
0
apple/__init__.py
Normal file
0
apple/__init__.py
Normal file
0
obsidian/__init__.py
Normal file
0
obsidian/__init__.py
Normal file
53
obsidian/examples/notes.txt
Normal file
53
obsidian/examples/notes.txt
Normal file
|
@ -0,0 +1,53 @@
|
|||
# 07.01.2025 (solo-2)
|
||||
|
||||
| Упражнение | Вес | Подходы |
|
||||
| --------------------------------------- | --------------------- | ----------- |
|
||||
| Разгибание ног сидя | 77-86-91-86 | 12-12-12-12 |
|
||||
| Сгибание ног лежа | 47 | 12-12-11-10 |
|
||||
| Жим от груди (рычаги) | 15х2-25х2-27.5х2-30х2 | 12-12-12-8 |
|
||||
| Отведение руки в кроссовере из за спины | 9-11-12 | 12-12-12 |
|
||||
| Кроссовер - отжимание на трицепс | 33 | 12-12-12-12 |
|
||||
|
||||
# 04.01.2025 (solo-1)
|
||||
|
||||
| Упражнение | Вес | Подходы |
|
||||
| --------------------------------------- | --------- | -------------- |
|
||||
| Подтягивания | | 9-7-5 |
|
||||
| Тяга горизонтального блока | 55-59 | 12-12-12-10 |
|
||||
| Тяга гантели в наклоне одной рукой | 30 | 10х2-10х2-10х2 |
|
||||
| Жим гантелей лежа | 18х2-20х2 | 12-12-11 |
|
||||
| Разведение рук в стороны (дельт машина) | 47 | 12-12-12 |
|
||||
| Трицепс машина | 77 | 12-12-12 |
|
||||
|
||||
|
||||
# 30.12.2024 (c166-115)
|
||||
|
||||
| Упражнение | Вес | Подходы |
|
||||
| ----------------------- | --------- | ----------- |
|
||||
| Подтягивания | | 11-8-6 |
|
||||
| Тяга гантелей на скамье | 22х2-28х2 | 12-10-10-10 |
|
||||
| Жим гантелей лежа | 16х2-28х2 | 12-10-6-7 |
|
||||
| Сведение рук пек дек | 47 | 12-12-12 |
|
||||
| Брусья 37 | 11-1011-10-10 |
|
||||
|
||||
# 27.12.2024 (c165-114)
|
||||
|
||||
| Упражнение | Вес | Подходы |
|
||||
| ------------------------ | --------- | ----------- |
|
||||
| Разгибание ног сидя | 65-82-91 | 12-12-12 |
|
||||
| Жим ногами | 100-150 | 12-10-10-10 |
|
||||
| Гиперэкстензия | 15 | 12-12-12 |
|
||||
| Жим гантелей сидя | 12х2-20х2 | 12-10-10-10 |
|
||||
| Разведение рук в стороны | 47 | 11-11-12 |
|
||||
|
||||
# 25.12.2024 (c164-113)
|
||||
|
||||
| Упражнение | Вес | Подходы |
|
||||
| ---------------------------------- | --------- | ----------- |
|
||||
| Тяга вертикального блока | 45-54-59 | 12-12-10-10 |
|
||||
| Тяга гантели в наклоне одной рукой | 30-32 | 10-10-10 |
|
||||
| Тяга горизонтального блока | 50 | 12-12-12 |
|
||||
| Жим гантелей лежа | 16х2-24х2 | 12-10-10-10 |
|
||||
| Сведение рук пек дек | 47 | 12-12-12 |
|
||||
| | | |
|
||||
|
106
obsidian/notes_parser.py
Normal file
106
obsidian/notes_parser.py
Normal file
|
@ -0,0 +1,106 @@
|
|||
import os
|
||||
import re
|
||||
import copy
|
||||
from typing import Dict, List, Tuple
|
||||
from pprint import pprint
|
||||
|
||||
current_directory = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
def get_current_path():
|
||||
return current_directory
|
||||
|
||||
|
||||
def get_obsidian_examples_file(example_file_name: str):
|
||||
return os.path.join(get_current_path(), f"examples/{example_file_name}")
|
||||
|
||||
|
||||
def read_example_file(example_file_name: str):
|
||||
path_to_example: str = get_obsidian_examples_file(example_file_name)
|
||||
with open(path_to_example, "r") as f:
|
||||
content = f.read()
|
||||
return content
|
||||
|
||||
|
||||
def parse_training_exercises(exercise_line: str) -> List[str]:
|
||||
stripped: List[str] = [entry.strip() for entry in exercise_line.split("|")][1:-1]
|
||||
for entry in stripped:
|
||||
if entry in ["Упражнение", "Вес", "Подходы"]:
|
||||
raise ValueError
|
||||
if stripped:
|
||||
if "---" in stripped[0]:
|
||||
raise ValueError
|
||||
if len(stripped) != 3:
|
||||
raise ValueError
|
||||
return {
|
||||
"name": stripped[0],
|
||||
"weight": stripped[1],
|
||||
"reps": stripped[2],
|
||||
}
|
||||
|
||||
|
||||
def parse_training_header(training_data_line: str) -> Tuple[bool, str, str, str]:
|
||||
pattern: str = r"#\s(?P<date>\d+.\d+.\d+)\s\((?P<trainer>.+)-(?P<year_counter>.+)\)"
|
||||
match = re.search(pattern, training_data_line)
|
||||
if match:
|
||||
date = match.group("date").strip()
|
||||
trainer = match.group("trainer").strip()
|
||||
year_count = match.group("year_counter").strip()
|
||||
|
||||
print(f"Date: {date}")
|
||||
print(f"Trainer: {trainer}")
|
||||
print(f"Year counter: {year_count}")
|
||||
return True, date, trainer, year_count
|
||||
return False, None, None, None
|
||||
|
||||
|
||||
def filter_training_data(training_data: str):
|
||||
cleaned_text = re.sub(r"^\s*?\n", "", training_data, flags=re.MULTILINE)
|
||||
return cleaned_text
|
||||
|
||||
|
||||
def parse_training_data():
|
||||
training_data: str = filter_training_data(read_example_file("notes.txt"))
|
||||
training_template: Dict = {
|
||||
"date": None,
|
||||
"trainer": None,
|
||||
"year_count": None,
|
||||
"exercises": [],
|
||||
}
|
||||
parsed_trainings: List[List[str]] = []
|
||||
current_training: Dict = {}
|
||||
lines = training_data.splitlines()
|
||||
for index, line in enumerate(lines):
|
||||
if index == len(lines) - 1:
|
||||
current_training["exercises"] = current_training["exercises"][1:]
|
||||
parsed_trainings.append(current_training)
|
||||
break
|
||||
header_parsed, date, trainer, year_count = parse_training_header(line)
|
||||
if header_parsed:
|
||||
if not current_training:
|
||||
pass
|
||||
else:
|
||||
current_training["exercises"] = current_training["exercises"][1:]
|
||||
parsed_trainings.append(current_training)
|
||||
current_training = copy.deepcopy(training_template)
|
||||
current_training["date"] = date
|
||||
current_training["trainer"] = trainer
|
||||
current_training["year_count"] = year_count
|
||||
try:
|
||||
# exr, weight, reps = parse_training_exercises(line)
|
||||
# current_training["exercises"].append(
|
||||
# f"Name: {exr}, Weight: {weight}, Reps: {reps}"
|
||||
# )
|
||||
|
||||
# current_training["exercises"].append(
|
||||
# {"name": exr, "weight": weight, "reps": reps}
|
||||
# )
|
||||
|
||||
exr = parse_training_exercises(line)
|
||||
current_training["exercises"].append(exr)
|
||||
except ValueError:
|
||||
pass
|
||||
return parsed_trainings
|
||||
|
||||
|
||||
pprint(parse_training_data()[1:])
|
0
parser.py
Normal file
0
parser.py
Normal file
0
utils/__init__.py
Normal file
0
utils/__init__.py
Normal file
Loading…
Reference in a new issue