Skip to content

Instantly share code, notes, and snippets.

@schoentoon
Created May 18, 2014 13:35
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 schoentoon/83718670df08f86c0222 to your computer and use it in GitHub Desktop.
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
#!/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