forked from letsRobot/letsrobot
-
Notifications
You must be signed in to change notification settings - Fork 19
/
robot_util.py
50 lines (40 loc) · 1.2 KB
/
robot_util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import requests
import time
import traceback
import ssl
import sys
import json
import logging
import networking
if (sys.version_info > (3, 0)):
import urllib.request as urllib2
from urllib.error import HTTPError
else:
import urllib2
from urllib2 import HTTPError
log = logging.getLogger('RemoTV.robot_util')
terminate=None
def terminate_controller():
log.info('Attempting to terminate controller...')
if terminate != None:
terminate.acquire()
# TODO : Think about rewriting this, and using request.
def getWithRetry(url, secure=True):
for retryNumber in range(2000):
try:
log.debug("GET %s", url)
if secure:
response = urllib2.urlopen(url).read()
else:
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
response = urllib2.urlopen(url, context=ctx).read()
break
except:
log.exception("could not open url %s", url)
#traceback.print_exc()
time.sleep(2)
return response.decode('utf-8')
def sendChatMessage(message):
networking.sendChatMessage(message)