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) address = Remote.find_tvs(first_only=True)
remote = Remote(address) remote = Remote(address)
key = raw_input('Enter pairing key: ') key = input('Enter pairing key: ')
remote.set_pairing_key(key) remote.set_pairing_key(key)
print("EXAMPLE: remote.send_command(INSERT_CMD_HERE, remote.session)") 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 re
import time import time
import socket import socket
import httplib from urllib import request, parse
from xml.etree import ElementTree from xml.etree import ElementTree
@ -52,14 +52,14 @@ class Remote():
addresses = [] addresses = []
while attempts > 0: while attempts > 0:
sock.sendto(request, ('239.255.255.250', 1900)) sock.sendto(request.encode(), ('239.255.255.250', 1900))
try: try:
response, address = sock.recvfrom(512) response, address = sock.recvfrom(512)
except: except:
attempts -= 1 attempts -= 1
continue continue
if re.search('LG', response): if re.search('LG', response.decode()):
if first_only: if first_only:
sock.close() sock.close()
return address[0] return address[0]
@ -90,11 +90,11 @@ class Remote():
POST the XML request to the configured TV and parse the response 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 = {'Content-Type': 'application/atom+xml'}
headers.update(extra_headers) headers.update(extra_headers)
http.request("POST", endpoint, content, headers=headers) url = parse.urlunparse(("http", self.ip_address + ":8080", endpoint, "", "", ""))
response = http.getresponse() req = request.Request(url, data=content.encode(), headers=headers)
response = request.urlopen(req)
tree = ElementTree.XML(response.read()) tree = ElementTree.XML(response.read())
return tree return tree