I am trying to rewrite a super simple html page dynamically after using socket to retrieve a value. Essentially this is pulling a track name from my squeezebox and trying to write it to html. The first part of line is always the same, but the track title needs to change. I'm sure it's super simple but I've spent hours trawling different sites and looking at diff methods, so time to ask for help.
HTML has a line in it as follows, among more:
<p class="GeneratedText">Someone Like You</p>
I am then trying to run the following to find that line. It's always the same line number but I tried with read lines, and I read it reads everything in anyway:
import socket
import urllib
import fileinput
import re
# connect to my squeebox - retricve the track name and clean up ready for insertion
clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clientsocket.connect(("192.168.1.10", 9090))
clientsocket.send("00:04:00:00:00:00 title ?\n")
str = clientsocket.recv(100)
title=str.strip( '00%3A00%3A00%3A00%3A00%3A00 title' );
result = urllib.unquote(title)
#try and overwrite the line in we.html so it looks like <p class="GeneratedText">Now playing track</p>
with open('we.html', 'r+') as f:
for line in f:
if re.match("(.*)p class(.*)",line):
data=line
print data
f.write( line.replace(data,'<p class="GeneratedText">'title'</p>'))