Skip to content

Commit

Permalink
Update __init__.py
Browse files Browse the repository at this point in the history
  • Loading branch information
younesStrittmatter authored May 20, 2024
1 parent 5afb2cc commit 15187b2
Showing 1 changed file with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def __save_patch(url, headers, _json):


def __get_request_results(url, headers):
# Fetch all submissions using pagination
all_submissions = []
while True:
data = __save_get(url, headers)
Expand All @@ -70,9 +69,7 @@ def __get_request_results_id(url, headers):
while True:
data = __save_get(url, headers)
url = data['_links']['next']['href']
# Concatenate the JSON object from the response
all_submissions.extend(data.get("results", []))
# Check if there are no more results
if url is None:
break

Expand Down Expand Up @@ -171,19 +168,21 @@ def _request_return(id: str, prolific_token: str):
_json=data,
)


def _approve(id: str, prolific_token: str):
__save_post(
f'https://api.prolific.com/api/v1/submissions/{id}/transition/',
headers={"Authorization": f"Token {prolific_token}"},
_json={"action": "APPROVE"}
)
f'https://api.prolific.com/api/v1/submissions/{id}/transition/',
headers={"Authorization": f"Token {prolific_token}"},
_json={"action": "APPROVE"},
)


def request_return_all(study_id: str, prolific_token: str):
submissions = _get_submissions_no_code_not_returned(study_id, prolific_token)
for id in submissions:
_request_return(id, prolific_token)


def approve_all_no_code(study_id: str, prolific_token: str):
submissions = _get_submissions_no_code_not_returned(study_id, prolific_token)
for id in submissions:
Expand Down Expand Up @@ -433,9 +432,17 @@ def _get_participants_by_status(study_id: str, prolific_token: str, status: str)
return [d['participant_id'] for d in results if d["status"] == status]


def _get_submissions_by_status(study_id: str, prolific_token: str, status: str):
results = _get_submissions(study_id, prolific_token)
return [d['id'] for d in results if d["status"] == status]


def get_participants_awaiting_review(study_id: str, prolific_token: str):
return _get_participants_by_status(study_id, prolific_token, 'AWAITING REVIEW')

def get_submissions_awaiting_review(study_id: str, prolific_token: str):
return _get_submissions_by_status(study_id, prolific_token, 'AWAITING REVIEW')


def get_participants_returned(study_id: str, prolific_token: str):
return _get_participants_by_status(study_id, prolific_token, 'RETURNED')
Expand All @@ -446,7 +453,7 @@ def get_participants_timed_out(study_id: str, prolific_token: str):


def approve_all(study_id: str, prolific_token: str):
submissions = get_participants_awaiting_review(study_id, prolific_token)
submissions = get_submissions_awaiting_review(study_id, prolific_token)
for id in submissions:
_approve(id, prolific_token)

Expand Down

0 comments on commit 15187b2

Please sign in to comment.