import rclpy
from rclpy.node import Node
from custom_messages.msg import Mypath2

class FileWriter(Node):
    
    def __init__(self):
        super().__init__("path_finder_publisher")
        self.pose_subscriber = self.create_subscription(Mypath2, '/route_coord', self.file_creator, 10)
        self.pose_subscriber

    def file_creator(self, msg: Mypath2):
        for pose in msg.poses:
            with open('thetas_list', 'a') as f:
                f.write(str(pose.theta) + '\n')

def main(args=None):
    rclpy.init(args=args)
    node = FileWriter()
    rclpy.spin(node)
    rclpy.shutdown()

if __name__ == '__main__':
    main()