-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
changename.py
52 lines (43 loc) · 1.79 KB
/
changename.py
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
import re
import os
#File paths
pathBuildGradle: str = os.path.join(".", "app", "build.gradle.kts")
pathStringRes: str = os.path.join(".", "app", "src", "prerelease", "res", "values", "strings.xml")
# Regex to find old string
findAppId: str = "(?<=applicationId = \")(.*?)(?=\")"
findAppName: str = "(?<=\"app_name\">)(.*?)(?=<)"
# Replace string
newAppPackage: str = "com.lagradost.cloudstream3xxx"
newAppName: str = "CloudStream XXX"
# Define functions
def replace_str_using_regex(path: str, regex: str, new_text: str):
try:
# Save current contents
text: str = ""
# Check file if exists
print(f"Checking filepath => {path}")
if os.path.exists(path):
# Read contents
with open(path, "r", encoding='utf-8') as file:
print("Read file..")
text: str = file.read()
#print("Old text => {0}".format(text))
file.close()
print("Reading file closed!")
# replace with new content
with open(path, "w", encoding='utf-8') as file:
print("Replacing file contents..")
newText: str = re.sub(regex, new_text, text)
#newText: str = text.replace("com.lagradost.cloudstream3", newAppPackage)
#print("New text => {0}".format(newText))
file.truncate(0)
print("File cleared!")
file.write(newText)
print("Done writing!")
file.close()
print("File closed!")
except Exception as ex:
print("Error => {0}: {1}".format(path, ex))
if __name__ == '__main__':
replace_str_using_regex(pathBuildGradle, findAppId, newAppPackage)
replace_str_using_regex(pathStringRes, findAppName, newAppName)