-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapp.py
More file actions
61 lines (49 loc) · 1.7 KB
/
app.py
File metadata and controls
61 lines (49 loc) · 1.7 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
import os
import re
# Screen dimensions
SCREEN_WIDTH = 1920
SCREEN_HEIGHT = 1080
# Conversion factors
VW_TO_PX = SCREEN_WIDTH / 100 # 19.2
VH_TO_PX = SCREEN_HEIGHT / 100 # 10.8
def vw_to_vh(value):
"""Convert vw value into vh"""
px = float(value) * VW_TO_PX
return px / VH_TO_PX
def convert_units(content):
"""
Replace vw with vh (via px conversion) and vh with vh (recalculated for consistency).
"""
# Replace vw → vh
content = re.sub(
r"(\d*\.?\d+)vw",
lambda m: f"{vw_to_vh(m.group(1)):.2f}vh",
content,
)
# Normalize vh (optional: keeps format consistent)
content = re.sub(
r"(\d*\.?\d+)vh",
lambda m: f"{float(m.group(1)):.2f}vh",
content,
)
return content
def scan_and_convert(directory):
"""
Walk through the directory, find matching files, and replace units.
"""
FILE_EXTENSIONS = [".scss", ".tsx"]
for root, _, files in os.walk(directory):
for file in files:
if any(file.endswith(ext) for ext in FILE_EXTENSIONS):
filepath = os.path.join(root, file)
with open(filepath, "r", encoding="utf-8") as f:
content = f.read()
new_content = convert_units(content)
if new_content != content:
with open(filepath, "w", encoding="utf-8") as f:
f.write(new_content)
print(f"Updated: {filepath}")
if __name__ == "__main__":
project_dir = "C:/Users/Administrator/Desktop/FiveM/QB/data/resources/[phone]/summit_phone/resources/web" # change this to your project path
scan_and_convert(project_dir)
print("✅ Conversion complete!")