Skip to content

Commit a84ddb6

Browse files
committed
Fixing bugs on creating projects
1 parent df48f0c commit a84ddb6

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
setup(
1515
name='tobiiglassesctrl',
16-
version='2.2.4',
16+
version='2.2.5',
1717
description='A Python controller for Tobii Pro Glasses 2',
1818
url='https://github.com/ddetommaso/TobiiGlassesPyController/',
19-
download_url='https://github.com/ddetommaso/TobiiGlassesPyController/archive/2.2.4.tar.gz',
19+
download_url='https://github.com/ddetommaso/TobiiGlassesPyController/archive/2.2.5.tar.gz',
2020
install_requires=['netifaces'],
2121
author='Davide De Tommaso',
2222
author_email='[email protected]',

tobiiglassesctrl/controller.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,26 @@
2424
import logging
2525
import struct
2626
import sys
27-
import netifaces
2827
import select
2928

3029
try:
31-
from urllib.parse import urlparse, urlencode
32-
from urllib.request import urlopen, Request
33-
from urllib.error import URLError, HTTPError
30+
import netifaces
31+
TOBII_DISCOVERY_ALLOWED = True
32+
except:
33+
TOBII_DISCOVERY_ALLOWED = False
34+
35+
try:
36+
from urllib.parse import urlparse, urlencode
37+
from urllib.request import urlopen, Request
38+
from urllib.error import URLError, HTTPError
3439
except ImportError:
35-
from urlparse import urlparse
36-
from urllib import urlencode
37-
from urllib2 import urlopen, Request, HTTPError, URLError
40+
from urlparse import urlparse
41+
from urllib import urlencode
42+
from urllib2 import urlopen, Request, HTTPError, URLError
3843

3944
socket.IPPROTO_IPV6 = 41
40-
#TOBII_DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%S+%f'#(Tobii Glasses controller uses Format %d/%m/%Y %H:%M:%S (this datetime format causes a crash if controller is used)
41-
TOBII_DATETIME_FORMAT = '%d/%m/%Y %H:%M:%S'
45+
TOBII_DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%S+%f'
46+
TOBII_DATETIME_FORMAT_HUMREAD = '%d/%m/%Y %H:%M:%S'
4247

4348
class TobiiGlassesController():
4449

@@ -109,6 +114,10 @@ def __disconnect__(self):
109114
return True
110115

111116
def __discover_device__(self):
117+
if TOBII_DISCOVERY_ALLOWED == False:
118+
logging.error("Device discovery is not available due to a missing dependency (netifaces)")
119+
exit(1)
120+
112121
logging.debug("Looking for a Tobii Pro Glasses 2 device ...")
113122
MULTICAST_ADDR = 'ff02::1'
114123
PORT = 13006
@@ -139,8 +148,8 @@ def __discover_device__(self):
139148
logging.debug("The discovery process did not find any device!")
140149
return (None, None)
141150

142-
def __get_current_datetime__(self):
143-
return datetime.datetime.now().replace(microsecond=0).strftime(TOBII_DATETIME_FORMAT)
151+
def __get_current_datetime__(self, timeformat=TOBII_DATETIME_FORMAT):
152+
return datetime.datetime.now().replace(microsecond=0).strftime(timeformat)
144153

145154
def __get_request__(self, api_action):
146155
url = self.base_url + api_action
@@ -305,7 +314,7 @@ def create_participant(self, project_id, participant_name = "DefaultUser", parti
305314

306315
if participant_id is None:
307316
data = {'pa_project': project_id,
308-
'pa_info': { 'EagleId': str(uuid.uuid5(uuid.NAMESPACE_DNS, self.participant_name.encode('utf-8'))),
317+
'pa_info': { 'EagleId': str(uuid.uuid5(uuid.NAMESPACE_DNS, self.participant_name)),
309318
'Name': self.participant_name,
310319
'Notes': participant_notes},
311320
'pa_created': self.__get_current_datetime__()}
@@ -320,8 +329,8 @@ def create_project(self, projectname = "DefaultProjectName"):
320329
project_id = self.get_project_id(projectname)
321330

322331
if project_id is None:
323-
data = {'pr_info' : {'CreationDate': self.__get_current_datetime__(),
324-
'EagleId': str(uuid.uuid5(uuid.NAMESPACE_DNS, self.participant_name.encode('utf-8'))),
332+
data = {'pr_info' : {'CreationDate': self.__get_current_datetime__(timeformat=TOBII_DATETIME_FORMAT_HUMREAD),
333+
'EagleId': str(uuid.uuid5(uuid.NAMESPACE_DNS, projectname)),
325334
'Name': projectname},
326335
'pr_created': self.__get_current_datetime__() }
327336
json_data = self.__post_request__('/api/projects', data)

0 commit comments

Comments
 (0)