Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import print_function
- import sys
- import uuid
- import urllib
- import json
- import time
- import PersistentData
- def name_to_uuid(name, page="https://api.mojang.com/users/profiles/minecraft/"):
- while True:
- path = page + name
- url = urllib.urlopen(path)
- NS = uuid.UUID('80c336a2-2226-11e4-89e8-0401211ac001')
- text = url.read()
- try:
- jdata = json.loads(text)
- except ValueError:
- ret = uuid.uuid5(NS, name)
- return ret
- try:
- ret = str(uuid.UUID(jdata["id"]))
- return ret
- except KeyError:
- if "TooManyRequestsException" in text:
- print("TooManyRequestsException, waiting 30 seconds", file=sys.stderr)
- error = 1
- time.sleep(30)
- else:
- ret = uuid.uuid5(NS, name)
- return ret
- if __name__ == "__main__":
- if len(sys.argv) > 1:
- path = sys.argv[1]
- else:
- path = "PlotData.json"
- n = PersistentData.Node()
- be = PersistentData.JSONBackend()
- be.Load(n, open(path, "r").read())
- d = n.Dict()
- new = {}
- new["ORE"] = {}
- new["ORE"]["Players"] = {}
- new["ORE"]["Plots"] = {}
- new["ORE"]["Size"] = d["ORE"]["Size"]
- new["ORE"]["Players"] = {name_to_uuid(name):{"Name":name, "remPlots":val["remPlots"]}
- for (name,val) in d["ORE"]["Players"].iteritems()}
- for k, v in d["ORE"]["Plots"].iteritems():
- new["ORE"]["Plots"][k] = v
- if v["status"] == 0:
- continue
- new["ORE"]["Plots"][k]["ownerid"] = name_to_uuid(v["owner"])
- del new["ORE"]["Plots"][k]["owner"]
- newn = PersistentData.Node()
- newbe = PersistentData.JSONBackend()
- newbe.LoadDict(new)
- text = newbe.Save(newn)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement