Last active
March 16, 2021 22:17
-
-
Save Crossedfall/e3425316fb6edc900e57b84c6738d2f3 to your computer and use it in GitHub Desktop.
This script checks through all the 'ChiselMessages' files, one for each map, and purges old or disliked Soapstone message. It will make a backup of each file before removing any engravings.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This script checks through all the 'ChiselMessages' files, one for each | |
map, and purges old or disliked Soapstone message. It will make a | |
backup of each file before removing any engravings. | |
------------------------------------------------------------------------ | |
This is free and unencumbered software released into the public domain. | |
Anyone is free to copy, modify, publish, use, compile, sell, or | |
distribute this software, either in source code form or as a compiled | |
binary, for any purpose, commercial or non-commercial, and by any | |
means. | |
In jurisdictions that recognize copyright laws, the author or authors | |
of this software dedicate any and all copyright interest in the | |
software to the public domain. We make this dedication for the benefit | |
of the public at large and to the detriment of our heirs and | |
successors. We intend this dedication to be an overt act of | |
relinquishment in perpetuity of all present and future rights to this | |
software under copyright law. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | |
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
OTHER DEALINGS IN THE SOFTWARE. | |
For more information, please refer to <http://unlicense.org/> | |
------------------------------------------------------------------------ | |
Created by Crossedfall | |
""" | |
import json | |
import shutil | |
from copy import deepcopy | |
from datetime import datetime | |
from pathlib import Path | |
BYOND_ERA = 946684800 | |
CURRENT_DATE = datetime.today().timestamp() | |
DATA_PATH = Path('.') #Change this so that the path points to .../data/npc_saves | |
def main(): | |
for filename in DATA_PATH.glob('**/ChiselMessages*.json'): | |
old_messages = 0 | |
disliked_messages = 0 | |
shutil.copyfile(filename, f'{filename}.bak') | |
data = None | |
with open(filename) as f: | |
data = json.load(f) | |
out_data = deepcopy(data) | |
for m in data['data']: | |
message_date = (int(m['realdate']) / 10) + BYOND_ERA | |
if message_date <= (CURRENT_DATE - 15778458): #Remove messages that are 6-months old | |
old_messages += 1 | |
out_data['data'].remove(m) | |
elif (len(m['like_keys']) < len(m['dislike_keys'])) or (len(m['like_keys']) < 5): | |
if message_date <= (CURRENT_DATE - 86400): #Only remove unpopular engravings that are at least 24-hours old. | |
disliked_messages += 1 | |
out_data['data'].remove(m) | |
with open(filename, 'w') as outfile: | |
json.dump(out_data, outfile) | |
print(f"Done with: {filename}\nRemoved {old_messages} old messages and {disliked_messages} disliked messages.\nRemaining messages: {len(out_data['data'])}") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment