| OLD | NEW |
| 1 # Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/ | 1 # Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/ |
| 2 # | 2 # |
| 3 # Permission is hereby granted, free of charge, to any person obtaining a | 3 # Permission is hereby granted, free of charge, to any person obtaining a |
| 4 # copy of this software and associated documentation files (the | 4 # copy of this software and associated documentation files (the |
| 5 # "Software"), to deal in the Software without restriction, including | 5 # "Software"), to deal in the Software without restriction, including |
| 6 # without limitation the rights to use, copy, modify, merge, publish, dis- | 6 # without limitation the rights to use, copy, modify, merge, publish, dis- |
| 7 # tribute, sublicense, and/or sell copies of the Software, and to permit | 7 # tribute, sublicense, and/or sell copies of the Software, and to permit |
| 8 # persons to whom the Software is furnished to do so, subject to the fol- | 8 # persons to whom the Software is furnished to do so, subject to the fol- |
| 9 # lowing conditions: | 9 # lowing conditions: |
| 10 # | 10 # |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 class MTurkRequestError(EC2ResponseError): | 35 class MTurkRequestError(EC2ResponseError): |
| 36 "Error for MTurk Requests" | 36 "Error for MTurk Requests" |
| 37 # todo: subclass from an abstract parent of EC2ResponseError | 37 # todo: subclass from an abstract parent of EC2ResponseError |
| 38 | 38 |
| 39 class MTurkConnection(AWSQueryConnection): | 39 class MTurkConnection(AWSQueryConnection): |
| 40 | 40 |
| 41 APIVersion = '2008-08-02' | 41 APIVersion = '2008-08-02' |
| 42 | 42 |
| 43 def __init__(self, aws_access_key_id=None, aws_secret_access_key=None, | 43 def __init__(self, aws_access_key_id=None, aws_secret_access_key=None, |
| 44 is_secure=False, port=None, proxy=None, proxy_port=None, | 44 is_secure=True, port=None, proxy=None, proxy_port=None, |
| 45 proxy_user=None, proxy_pass=None, | 45 proxy_user=None, proxy_pass=None, |
| 46 host=None, debug=0, | 46 host=None, debug=0, |
| 47 https_connection_factory=None): | 47 https_connection_factory=None): |
| 48 if not host: | 48 if not host: |
| 49 if config.has_option('MTurk', 'sandbox') and config.get('MTurk', 'sa
ndbox') == 'True': | 49 if config.has_option('MTurk', 'sandbox') and config.get('MTurk', 'sa
ndbox') == 'True': |
| 50 host = 'mechanicalturk.sandbox.amazonaws.com' | 50 host = 'mechanicalturk.sandbox.amazonaws.com' |
| 51 else: | 51 else: |
| 52 host = 'mechanicalturk.amazonaws.com' | 52 host = 'mechanicalturk.amazonaws.com' |
| 53 | 53 |
| 54 AWSQueryConnection.__init__(self, aws_access_key_id, | 54 AWSQueryConnection.__init__(self, aws_access_key_id, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 if keywords: | 87 if keywords: |
| 88 params['Keywords'] = self.get_keywords_as_string(keywords) | 88 params['Keywords'] = self.get_keywords_as_string(keywords) |
| 89 | 89 |
| 90 if approval_delay is not None: | 90 if approval_delay is not None: |
| 91 d = self.duration_as_seconds(approval_delay) | 91 d = self.duration_as_seconds(approval_delay) |
| 92 params['AutoApprovalDelayInSeconds'] = d | 92 params['AutoApprovalDelayInSeconds'] = d |
| 93 | 93 |
| 94 if qual_req is not None: | 94 if qual_req is not None: |
| 95 params.update(qual_req.get_as_params()) | 95 params.update(qual_req.get_as_params()) |
| 96 | 96 |
| 97 return self._process_request('RegisterHITType', params) | 97 return self._process_request('RegisterHITType', params, [('HITTypeId', H
ITTypeId)]) |
| 98 |
| 98 | 99 |
| 99 def set_email_notification(self, hit_type, email, event_types=None): | 100 def set_email_notification(self, hit_type, email, event_types=None): |
| 100 """ | 101 """ |
| 101 Performs a SetHITTypeNotification operation to set email | 102 Performs a SetHITTypeNotification operation to set email |
| 102 notification for a specified HIT type | 103 notification for a specified HIT type |
| 103 """ | 104 """ |
| 104 return self._set_notification(hit_type, 'Email', email, event_types) | 105 return self._set_notification(hit_type, 'Email', email, event_types) |
| 105 | 106 |
| 106 def set_rest_notification(self, hit_type, url, event_types=None): | 107 def set_rest_notification(self, hit_type, url, event_types=None): |
| 107 """ | 108 """ |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 once. | 554 once. |
| 554 | 555 |
| 555 test: a QuestionForm | 556 test: a QuestionForm |
| 556 | 557 |
| 557 answer_key: an XML string of your answer key, for automatically | 558 answer_key: an XML string of your answer key, for automatically |
| 558 scored qualification tests. | 559 scored qualification tests. |
| 559 (Consider implementing an AnswerKey class for this to support.) | 560 (Consider implementing an AnswerKey class for this to support.) |
| 560 | 561 |
| 561 test_duration: the number of seconds a worker has to complete the test. | 562 test_duration: the number of seconds a worker has to complete the test. |
| 562 | 563 |
| 563 auto_granted: if True, requests for the Qualification are granted immedi
ately. | 564 auto_granted: if True, requests for the Qualification are granted |
| 564 Can't coexist with a test. | 565 immediately. Can't coexist with a test. |
| 565 | 566 |
| 566 auto_granted_value: auto_granted qualifications are given this value. | 567 auto_granted_value: auto_granted qualifications are given this value. |
| 567 | 568 |
| 568 """ | 569 """ |
| 569 | 570 |
| 570 params = {'Name' : name, | 571 params = {'Name' : name, |
| 571 'Description' : description, | 572 'Description' : description, |
| 572 'QualificationTypeStatus' : status, | 573 'QualificationTypeStatus' : status, |
| 573 } | 574 } |
| 574 if retry_delay is not None: | 575 if retry_delay is not None: |
| 575 params['RetryDelay'] = retry_delay | 576 params['RetryDelayInSeconds'] = retry_delay |
| 576 | 577 |
| 577 if test is not None: | 578 if test is not None: |
| 578 assert(isinstance(test, QuestionForm)) | 579 assert(isinstance(test, QuestionForm)) |
| 579 assert(test_duration is not None) | 580 assert(test_duration is not None) |
| 580 params['Test'] = test.get_as_xml() | 581 params['Test'] = test.get_as_xml() |
| 581 | 582 |
| 582 if test_duration is not None: | 583 if test_duration is not None: |
| 583 params['TestDurationInSeconds'] = test_duration | 584 params['TestDurationInSeconds'] = test_duration |
| 584 | 585 |
| 585 if answer_key is not None: | 586 if answer_key is not None: |
| 586 if isinstance(answer_key, basestring): | 587 if isinstance(answer_key, basestring): |
| 587 params['AnswerKey'] = answer_key # xml | 588 params['AnswerKey'] = answer_key # xml |
| 588 else: | 589 else: |
| 589 raise TypeError | 590 raise TypeError |
| 590 # Eventually someone will write an AnswerKey class. | 591 # Eventually someone will write an AnswerKey class. |
| 591 | 592 |
| 592 if auto_granted: | 593 if auto_granted: |
| 593 assert(test is False) | 594 assert(test is None) |
| 594 params['AutoGranted'] = True | 595 params['AutoGranted'] = True |
| 595 params['AutoGrantedValue'] = auto_granted_value | 596 params['AutoGrantedValue'] = auto_granted_value |
| 596 | 597 |
| 597 if keywords: | 598 if keywords: |
| 598 params['Keywords'] = self.get_keywords_as_string(keywords) | 599 params['Keywords'] = self.get_keywords_as_string(keywords) |
| 599 | 600 |
| 600 return self._process_request('CreateQualificationType', params, | 601 return self._process_request('CreateQualificationType', params, |
| 601 [('QualificationType', QualificationType),]
) | 602 [('QualificationType', QualificationType),]
) |
| 602 | 603 |
| 603 def get_qualification_type(self, qualification_type_id): | 604 def get_qualification_type(self, qualification_type_id): |
| (...skipping 18 matching lines...) Expand all Loading... |
| 622 | 623 |
| 623 params = {'QualificationTypeId' : qualification_type_id } | 624 params = {'QualificationTypeId' : qualification_type_id } |
| 624 | 625 |
| 625 if description is not None: | 626 if description is not None: |
| 626 params['Description'] = description | 627 params['Description'] = description |
| 627 | 628 |
| 628 if status is not None: | 629 if status is not None: |
| 629 params['QualificationTypeStatus'] = status | 630 params['QualificationTypeStatus'] = status |
| 630 | 631 |
| 631 if retry_delay is not None: | 632 if retry_delay is not None: |
| 632 params['RetryDelay'] = retry_delay | 633 params['RetryDelayInSeconds'] = retry_delay |
| 633 | 634 |
| 634 if test is not None: | 635 if test is not None: |
| 635 assert(isinstance(test, QuestionForm)) | 636 assert(isinstance(test, QuestionForm)) |
| 636 params['Test'] = test.get_as_xml() | 637 params['Test'] = test.get_as_xml() |
| 637 | 638 |
| 638 if test_duration is not None: | 639 if test_duration is not None: |
| 639 params['TestDuration'] = test_duration | 640 params['TestDurationInSeconds'] = test_duration |
| 640 | 641 |
| 641 if answer_key is not None: | 642 if answer_key is not None: |
| 642 if isinstance(answer_key, basestring): | 643 if isinstance(answer_key, basestring): |
| 643 params['AnswerKey'] = answer_key # xml | 644 params['AnswerKey'] = answer_key # xml |
| 644 else: | 645 else: |
| 645 raise TypeError | 646 raise TypeError |
| 646 # Eventually someone will write an AnswerKey class. | 647 # Eventually someone will write an AnswerKey class. |
| 647 | 648 |
| 648 if auto_granted is not None: | 649 if auto_granted is not None: |
| 649 params['AutoGranted'] = auto_granted | 650 params['AutoGranted'] = auto_granted |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 now = datetime.datetime.utcnow() | 814 now = datetime.datetime.utcnow() |
| 814 expiration = datetime.datetime.strptime(self.Expiration, '%Y-%m-%dT%
H:%M:%SZ') | 815 expiration = datetime.datetime.strptime(self.Expiration, '%Y-%m-%dT%
H:%M:%SZ') |
| 815 expired = (now >= expiration) | 816 expired = (now >= expiration) |
| 816 else: | 817 else: |
| 817 raise ValueError("ERROR: Request for expired property, but no Expira
tion in HIT!") | 818 raise ValueError("ERROR: Request for expired property, but no Expira
tion in HIT!") |
| 818 return expired | 819 return expired |
| 819 | 820 |
| 820 # are we there yet? | 821 # are we there yet? |
| 821 expired = property(_has_expired) | 822 expired = property(_has_expired) |
| 822 | 823 |
| 824 class HITTypeId(BaseAutoResultElement): |
| 825 """ |
| 826 Class to extract an HITTypeId structure from a response |
| 827 """ |
| 828 |
| 829 pass |
| 830 |
| 823 class Qualification(BaseAutoResultElement): | 831 class Qualification(BaseAutoResultElement): |
| 824 """ | 832 """ |
| 825 Class to extract an Qualification structure from a response (used in | 833 Class to extract an Qualification structure from a response (used in |
| 826 ResultSet) | 834 ResultSet) |
| 827 | 835 |
| 828 Will have attributes named as per the Developer Guide such as | 836 Will have attributes named as per the Developer Guide such as |
| 829 QualificationTypeId, IntegerValue. Does not seem to contain GrantTime. | 837 QualificationTypeId, IntegerValue. Does not seem to contain GrantTime. |
| 830 """ | 838 """ |
| 831 | 839 |
| 832 pass | 840 pass |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 """ | 909 """ |
| 902 | 910 |
| 903 def __init__(self, connection): | 911 def __init__(self, connection): |
| 904 BaseAutoResultElement.__init__(self, connection) | 912 BaseAutoResultElement.__init__(self, connection) |
| 905 self.fields = [] | 913 self.fields = [] |
| 906 self.qid = None | 914 self.qid = None |
| 907 | 915 |
| 908 def endElement(self, name, value, connection): | 916 def endElement(self, name, value, connection): |
| 909 if name == 'QuestionIdentifier': | 917 if name == 'QuestionIdentifier': |
| 910 self.qid = value | 918 self.qid = value |
| 911 elif name in ['FreeText', 'SelectionIdentifier'] and self.qid: | 919 elif name in ['FreeText', 'SelectionIdentifier', 'OtherSelectionText'] a
nd self.qid: |
| 912 self.fields.append((self.qid,value)) | 920 self.fields.append( value ) |
| 913 elif name == 'Answer': | |
| 914 self.qid = None | |
| OLD | NEW |