Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/python3
- import os
- # You need to have pyyaml installed
- import yaml
- simplehomespath = "../server/plugins/SimpleHomes/Homes.yml"
- new_data={}
- player_homes=[]
- class Home:
- pass
- def get_yaml(path):
- f = open(path)
- # use safe_load instead load
- dataMap = yaml.safe_load(f)
- f.close()
- return dataMap
- def process_data(dataMap):
- for k1 in dataMap:
- # key nest-1
- # print("\n" + k1)
- d = dataMap[k1]
- for k2 in d:
- item = Home()
- item.playername = k1
- # key nest-2
- item.homename=k2
- item.x=d[k2]['x']
- item.y=d[k2]['y']
- item.z=d[k2]['z']
- item.world=d[k2]['world']
- # print(k2, ':', d[k2])
- # attrs=vars(item)
- # print (', '.join("%s: %s" % item for item in attrs.items()))
- player_homes.append(item)
- # populate player_homes list
- process_data(get_yaml(simplehomespath))
- # get data in dictionary
- for home in player_homes:
- index = len(new_data) + 1
- defaulthome = "false"
- if home.homename == "default":
- home.homename = "null"
- defaulthome = "true"
- else:
- home.homename = '"' + home.homename + '"'
- home_dict = {"==": "Home",
- "id": index,
- "lastModified": 1423599176803,
- "dateCreated": 1423598140119,
- "world": home.world,
- "x": float(home.x),
- "y": float(home.y),
- "z": float(home.z),
- "pitch": 0.0,
- "yaw": 180.0,
- "name": home.homename,
- "player_name": home.playername,
- "updatedBy": home.playername,
- "bedHome": "false",
- "defaultHome": defaulthome
- }
- new_data[index] = home_dict
- # output dictionary how HSP plguin likes
- for k in sorted(new_data):
- print(" '%s':" % k)
- for i in new_data[k]:
- print(" %s: %s" % (i, new_data[k][i]))
Advertisement
Add Comment
Please, Sign In to add comment