import pathlib
import random
import re
mouse_names = [
"mouse1",
"mouse2",
"mouse3",
]
random.seed(1985) # Seed the random number generator so we get the same "random" numbers each time
mouse_codes = {name: random.randint(100000, 999999) for name in mouse_names}
# mouse_codes = {
# "mouse1": 12345,
# "mouse2": 23456,
# "mouse3": 34567,
# }
cwd = Path(".")
for path in cwd.glob("2022*"):
# Grab contents of XML file
if not path.is_dir():
continue
filepath = path / "Series.vxml"
if not filepath.is_file():
raise FileNotFoundError("whoops")
with open(filepath, "r") as fh:
xml = fh.read()
# Determine name, replace with code
namematch = re.search(f'name="([^"]+)"', xml)
if not namematch:
raise ValueError(f"unable to determine name for {str(filepath)}")
name = namematch.group(1)
if name not in mouse_codes:
raise ValueError(f"no code for mouse {name}")
new_code = mouse_codes[name]
xml = re.sub(r'name="[^"]+"', f'name="{new_code}"', xml)
# Overwrite the XML file
with open(filepath, "w") as fh:
print(xml, end="", file=fh)
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing