-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort_favs.py
More file actions
60 lines (47 loc) · 2.08 KB
/
Copy pathsort_favs.py
File metadata and controls
60 lines (47 loc) · 2.08 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
import os
from typing import List
class Line:
index: int = 0
content_sort: str = ""
content_full: str = ""
def __init__(self, index, content_full):
self.index = index
self.content_full = content_full
def cut_out_the_bs(input: str):
# not very nice way to get rid of the months in THC but it'll do
months: List[str] = ["1 jan", "2 feb", "3 mar", "4 apr", "5 may", "6 jun",
"7 jul", "8 aug", "9 sep", "10 oct", "11 nov", "12 dec"]
folder_name = input.split("/", 1)[1].lower()
no_thc_month = ""
m: str
for m in months:
if m in folder_name:
no_thc_month = folder_name[len(m) + 3:]
break
else:
no_thc_month = folder_name
no_jayce = no_thc_month[13:] if no_thc_month.startswith("(-[jayce]-) -") else no_thc_month
no_parens = no_jayce[no_jayce.index(
")") + 1:] if no_jayce.startswith("(") and not no_jayce.endswith(")") else no_jayce
no_dashes = no_parens[no_parens.index(
"-") + 1:] if no_parens.startswith("-") and not no_parens.endswith("-") else no_parens
no_brackets = no_dashes[no_dashes.index(
"]") + 1:] if no_dashes.startswith("[") and not no_dashes.endswith("]") else no_dashes
no_brackets = no_brackets.lstrip()
no_brackets2 = no_brackets[no_brackets.index(
"]") + 1:] if no_brackets.startswith("[") and not no_brackets.endswith("]") else no_brackets
fixed_input = no_brackets2.lstrip()
return fixed_input
lines_list = []
os.rename("favorites.txt", "favorites.txt.bak")
with open("favorites.txt.bak", "r") as file:
all_lines = file.readlines()
for i in range(len(all_lines)):
newline = Line(i, all_lines[i])
newline.content_sort = cut_out_the_bs(newline.content_full)
lines_list.append(newline)
sorted_lines = sorted(lines_list, key=(lambda x: x.content_sort))
with open("favorites.txt", "w") as file:
for line in sorted_lines:
file.write(line.content_full)
print("Old favourites file has been renamed to \'favorites.txt.bak\', in case something went horribly wrong.")