Skip to content

Instantly share code, notes, and snippets.

@13steinj
Created January 27, 2016 16:34
Show Gist options
  • Select an option

  • Save 13steinj/a5bfefa37b97eede36c9 to your computer and use it in GitHub Desktop.

Select an option

Save 13steinj/a5bfefa37b97eede36c9 to your computer and use it in GitHub Desktop.

Revisions

  1. 13steinj created this gist Jan 27, 2016.
    36 changes: 36 additions & 0 deletions updateredditheaders.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    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()