Track your Anki study sessions directly into Yōten.
at master 68 lines 2.0 kB view raw
1import urllib.parse 2from typing import TYPE_CHECKING, Any 3 4if TYPE_CHECKING: 5 from PyQt6.QtWidgets import QComboBox 6 from .session_tracker import StudySession 7 8 9def get_default_config() -> dict: 10 return { 11 'yoten_url': 'https://yoten.app/session/new', 12 'activity_id': '81', 13 'default_language': 'en', 14 'min_cards_threshold': 5, 15 'min_duration_threshold': 30 16 } 17 18 19def get_config_value(config: dict, key: str) -> Any: 20 defaults = get_default_config() 21 return config.get(key, defaults.get(key)) 22 23 24def get_current_config(module_name: str) -> dict: 25 from aqt import mw 26 return mw.addonManager.getConfig(module_name) 27 28 29def build_yoten_url(session: 'StudySession', language_code: str, config: dict) -> str: 30 base_url = get_config_value(config, 'yoten_url') 31 activity_id = get_config_value(config, 'activity_id') 32 33 hours, minutes, seconds = session.duration_parts 34 35 params = { 36 'language_code': language_code, 37 'duration_hours': str(hours), 38 'duration_minutes': str(minutes), 39 'duration_seconds': str(seconds), 40 'description': session.description, 41 'activity_id': activity_id 42 } 43 44 query_string = urllib.parse.urlencode(params) 45 return f"{base_url}?{query_string}" 46 47 48def populate_language_combo(combo_box: 'QComboBox', default_code: str = 'en') -> None: 49 from .language_codes import get_common_languages 50 51 common_languages = get_common_languages() 52 53 for idx, (code, name) in enumerate(common_languages): 54 # Handle separator item 55 if code == "---": 56 combo_box.addItem(name, code) 57 # Make separator item disabled (not selectable) 58 model = combo_box.model() 59 item = model.item(idx) 60 if item: 61 item.setEnabled(False) 62 else: 63 combo_box.addItem(f"{name} ({code})", code) 64 65 # Set default selection 66 index = combo_box.findData(default_code) 67 if index >= 0: 68 combo_box.setCurrentIndex(index)