29.12.2016, 16:36
so ist das script etwas kürzer.
Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import socket
import time
UDP_IP = "127.0.0.1"
UDP_PORT = 5005
LOOP_COUNT = 14
def main():
time.sleep(10) # wait for ... ?
# Path to stations preset file
with open('/home/pi/.kodi/addons/plugin.program.radioFM/resources/stations','r') as file:
# Read the stations file into string and close it
data = file.readlines()
# Take first line from station list and split it up by spaces
item = data[0]
requestedFrequency = item.split(' ')
# Use the first value of the split string for first station to tune radio to
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto("radio_tune_" + requestedFrequency[0] + "\0", (UDP_IP, UDP_PORT))
for _ in range(LOOP_COUNT):
sock.sendto("radio_volume_plus", (UDP_IP, UDP_PORT))
sock.close()
if __name__ == '__main__':
main()