Created
May 18, 2014 13:35
-
-
Save schoentoon/83718670df08f86c0222 to your computer and use it in GitHub Desktop.
Pretty much the same as https://gist.github.com/schoentoon/6176047 but this will run forever and run with inotify itself
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
#!/usr/bin/python | |
from nbt import * # https://github.com/twoolie/NBT | |
import json | |
def generate(): | |
nbtfile = nbt.NBTFile("/path/to/scoreboard.dat", 'rb') | |
deaths=dict() | |
for tag in nbtfile["data"]["PlayerScores"]: | |
if str(tag["Objective"]) == "Deaths": #Assuming the objective keeping track of the deaths is called "deaths" | |
deaths[str(tag["Name"])] = int(str(tag["Score"])) | |
deaths = sorted(deaths.items(), key=lambda x:x[1]) | |
deaths.reverse() | |
with open('/output/deaths.json', 'w') as outfile: | |
json.dump(deaths, outfile) | |
import pyinotify | |
wm = pyinotify.WatchManager() # Watch Manager | |
mask = pyinotify.IN_CLOSE_WRITE # watched events | |
class EventHandler(pyinotify.ProcessEvent): | |
def process_IN_CLOSE_WRITE(self, event): | |
if event.pathname.endswith("scoreboard.dat"): | |
print "Regenerating" | |
generate() | |
handler = EventHandler() | |
notifier = pyinotify.Notifier(wm, handler) | |
wdd = wm.add_watch('/path/to/world/data', mask, rec=True) | |
notifier.loop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment