from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage import settings from .models import Constants import time import boto3 def vars_for_all_templates(self): return { 'experiment_starting_time': self.session.config.get('experiment_starting_time', ''), } class WorkerID(Page): live_method = 'live_method' form_model = 'player' form_fields = ['workerid'] # form_fields = ['workerid', 'ip', # 'language', 'region', 'locality' ,'city', 'postcode', # 'network','timeZone','utcOffset','latitude','longitude', # 'tor','vpn','proxy' # ] def js_vars(self): return dict( data_received=self.player.data_received, ) def is_displayed(self): self.player.workerid = self.participant.label return 1 def before_next_page(self): if not self.timeout_happened: if not self.session.config.get('debug',False): access_key_id = self.session.config['access_key_id'] secret_access_key = self.session.config['secret_access_key'] if self.session.config.get('sandbox',False): # sandbox Qid = self.session.config['Qid_sandbox'] mturk = boto3.client( service_name='mturk', aws_access_key_id=access_key_id, aws_secret_access_key=secret_access_key, region_name='us-east-1', endpoint_url="https://mturk-requester-sandbox.us-east-1.amazonaws.com", ) else: # live production Qid = self.session.config['Qid'] mturk = boto3.client( service_name='mturk', aws_access_key_id=access_key_id, aws_secret_access_key=secret_access_key, region_name='us-east-1', ) mturk.associate_qualification_with_worker( QualificationTypeId=Qid, WorkerId=self.player.workerid, IntegerValue=1, SendNotification=False ) self.participant.vars['workerid'] = self.player.workerid user_agent_string = self.request.META['HTTP_USER_AGENT'] self.player.agent_string = user_agent_string print('User agent string:', user_agent_string) # This part checks for the operating system if 'Macintosh' in user_agent_string: self.player.machine = 'Macintosh' elif 'Windows' in user_agent_string: self.player.machine = 'Windows' else: self.player.machine = 'Other' # This part checks for the browser if 'Chrome' in user_agent_string: self.player.browser = 'Chrome' elif 'Edge' in user_agent_string: self.player.browser = 'Edge' elif 'Firefox' in user_agent_string: self.player.browser = 'Firefox' elif 'Safari' in user_agent_string and 'Chrome' not in user_agent_string and 'Edge' not in user_agent_string: self.player.browser = 'Safari' elif 'MSIE' in user_agent_string: self.player.browser = 'InternetExplorer' else: self.player.browser = 'Other' print('setting consent: ',self.player.consent) self.player.consent = True print('after setting consent: ',self.player.consent) class EndInfo(Page): def js_vars(self): return dict( data_received=self.player.data_received, ) page_sequence = [ WorkerID, EndInfo, ]