-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
126 lines (95 loc) · 2.67 KB
/
utils.py
File metadata and controls
126 lines (95 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
"""
Utility functions for PoE Stats Tracker
Common helper functions used across modules
"""
import time
def format_time(seconds):
"""
Format seconds into a readable time string
Args:
seconds: Time in seconds (float or int)
Returns:
str: Formatted time string like "1h 23m" or "5m 42s"
"""
if seconds is None:
return "N/A"
hours = int(seconds // 3600)
minutes = int((seconds % 3600) // 60)
secs = int(seconds % 60)
if hours > 0:
return f"{hours}h {minutes}m"
else:
return f"{minutes}m {secs}s"
def get_current_timestamp():
"""Get current timestamp as float"""
return time.time()
def validate_inventory_position(item, x=0, y=0):
"""
Check if an item is at a specific inventory position
Args:
item: Item dictionary from API
x: X coordinate (default 0)
y: Y coordinate (default 0)
Returns:
bool: True if item is at specified position
"""
return item.get('x') == x and item.get('y') == y
def extract_tier_from_typeline(type_line):
"""
Extract tier number from typeLine string
Args:
type_line: String like "Waystone (Tier 15)"
Returns:
str: Tier number or "Unknown"
"""
if not type_line or 'Tier' not in type_line:
return "Unknown"
import re
tier_match = re.search(r'Tier (\d+)', type_line)
return tier_match.group(1) if tier_match else "Unknown"
def clean_mod_text(mod):
"""
Clean and validate mod text
Args:
mod: Raw mod string
Returns:
str or None: Cleaned mod text or None if invalid
"""
if not mod:
return None
clean_mod = mod.strip()
return clean_mod if clean_mod else None
def create_empty_map_info(source="unknown"):
"""
Create an empty map info structure
Args:
source: Source identifier for the map info
Returns:
dict: Empty map info structure
"""
return {
'map_name': 'Unknown',
'level': 'Unknown',
'prefixes': [],
'suffixes': [],
'area_modifiers': {},
'source': source,
'seed': 'unknown'
}
def safe_get_nested_value(data, keys, default=None):
"""
Safely get nested dictionary value
Args:
data: Dictionary to search
keys: List of keys to traverse
default: Default value if key not found
Returns:
Any: Value at nested key or default
"""
current = data
try:
for key in keys:
current = current[key]
return current
except (KeyError, TypeError, IndexError):
return default