Skip to content

Commit

Permalink
Create year_update.py
Browse files Browse the repository at this point in the history
  • Loading branch information
marticliment committed Dec 30, 2021
1 parent ea773fd commit 60bd6e3
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions misc/year_update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import glob, os




OLDSTR = b"2021"

NEWSTR = b"""2022"""

input(f"Path is \"{os.getcwd()}\" Press [INTRO] to contniue")
print()
print()
print("Lang files to update: ")

for ext in ["py", "txt", "md", "html", "js"]:
for file in glob.glob(f"**/*.{ext}", recursive=True):
if "year_update" not in file:
print(" -", file)
print()
input("Press [INTRO] to contniue")

print()
print()
print("old string:", OLDSTR)
print("new string:", NEWSTR)
print()
input("Press [INTRO] to contniue")

for ext in ["py", "txt", "md", "html", "js"]:
for file in glob.glob(f"**/*.{ext}", recursive=True):
print("Processing", file, "...")
if "year_update" not in file:
try:
with open(file, "rb") as f:
contents = f.read()
if OLDSTR in contents:
with open(file, "wb") as f:
f.write(contents.replace(OLDSTR, NEWSTR))

print("🟢", file, "has been updated successfully")
else:
print("⚪", file, "has no occurrences of the substring")
except Exception as e:
print("🟥", file, "has not been updated:", str(e))

input("Finished, press [INTRO] to close")

0 comments on commit 60bd6e3

Please sign in to comment.