Skip to content

Instantly share code, notes, and snippets.

@prayagverma
Forked from 13steinj/updateredditheaders.py
Created January 27, 2016 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prayagverma/2f0596fec5f2f3ab093f to your computer and use it in GitHub Desktop.
Save prayagverma/2f0596fec5f2f3ab093f to your computer and use it in GitHub Desktop.
Update's reddit's headers to the current year
import os
from datetime import datetime
skipped_endings = ['.so', '.pyc', '.ico', '.png', '.jpg', '.jpeg', '.gif', '.o']
skipped_files = [
'r2/r2/public/static/inbound-email-policy.html' # when this file gets run through, something happens to it's endings, I don't know legal validity stuff.
]
current_year_digits = int(str(datetime.now().year)[2:])
file_list = []
for walker in os.walk('reddit'):
if walker[2]:
for file in walker[2]:
file_list.append(os.path.join(walker[0], file))
else:
file_list.append(walker[0])
file_list = [f for f in file_list if os.path.isfile(f) and ('.git/' not in f)]
for filename in file_list:
if any(filename.endswith(ending) for ending in skipped_endings):
continue
if any(filename.endswith(skipped) for skipped in skipped_files):
continue
file = open(filename, 'r')
print(filename)
data = file.read()
for i in range(6, current_year_digits):
data = data.replace(
"All portions of the code written by reddit are Copyright (c) 2006-20{0}".format(i),
"All portions of the code written by reddit are Copyright (c) 2006-20{0}".format(current_year_digits)
)
data = data.replace(
"Attribution Copyright Notice: Copyright (c) 2006-20{0} reddit Inc. All Rights".format(i),
"Attribution Copyright Notice: Copyright (c) 2006-20{0} reddit Inc. All Rights".format(current_year_digits)
)
file.close()
file = open(filename, 'w')
file.write(data)
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment