Switch to python3

This commit is contained in:
sqozz 2019-01-31 18:56:19 +01:00
parent 4a2c03cc5f
commit 30e6ec309e
2 changed files with 7 additions and 7 deletions

View File

@ -4,7 +4,7 @@ if __name__ == "__main__":
address = Remote.find_tvs(first_only=True)
remote = Remote(address)
key = raw_input('Enter pairing key: ')
key = input('Enter pairing key: ')
remote.set_pairing_key(key)
print("EXAMPLE: remote.send_command(INSERT_CMD_HERE, remote.session)")

12
lg.py
View File

@ -3,7 +3,7 @@ from __future__ import unicode_literals
import re
import time
import socket
import httplib
from urllib import request, parse
from xml.etree import ElementTree
@ -52,14 +52,14 @@ class Remote():
addresses = []
while attempts > 0:
sock.sendto(request, ('239.255.255.250', 1900))
sock.sendto(request.encode(), ('239.255.255.250', 1900))
try:
response, address = sock.recvfrom(512)
except:
attempts -= 1
continue
if re.search('LG', response):
if re.search('LG', response.decode()):
if first_only:
sock.close()
return address[0]
@ -90,11 +90,11 @@ class Remote():
POST the XML request to the configured TV and parse the response
"""
http = httplib.HTTPConnection(self.ip_address, port=8080)
headers = {'Content-Type': 'application/atom+xml'}
headers.update(extra_headers)
http.request("POST", endpoint, content, headers=headers)
response = http.getresponse()
url = parse.urlunparse(("http", self.ip_address + ":8080", endpoint, "", "", ""))
req = request.Request(url, data=content.encode(), headers=headers)
response = request.urlopen(req)
tree = ElementTree.XML(response.read())
return tree