You could just replace:
layers = iface.legendInterface().layers()
layers = iface.legendInterface().layers()
with
layers = [layer for layer in QgsProject.instance().mapLayers().values()]
layers = [layer for layer in QgsProject.instance().mapLayers().values()]