Ejemplo n.º 1
0
    def get_survey_responses(self, verbose=False):
        """Retrieve pandas DataFrame containing responses for a survey"""

        progress_status = "inProgress"

        download_url = self.endpoint("surveys/{0}/export-responses".format(
            self.survey_id))

        # Create Data Export
        download_payload = {"format": self.file_format}
        download_response = issue_request("POST",
                                          download_url,
                                          data=download_payload,
                                          headers=self.headers)
        progress_id = download_response["result"]["progressId"]

        # Check on Data Export Progress and waiting until export is ready
        while progress_status != "complete" and progress_status != "failed":
            if verbose:
                print("progress_status: {}".format(progress_status))
            check_url = join(download_url, progress_id)
            check_response = issue_request("GET",
                                           check_url,
                                           headers=self.headers)
            check_progress = check_response["result"]["percentComplete"]
            if verbose:
                print("Download is " + str(check_progress) + " complete")
            progress_status = check_response["result"]["status"]

        # Check for error
        if progress_status is "failed":
            raise Exception("export failed")

        file_id = check_response["result"]["fileId"]

        # Retrieve zipfile and extract and read in CSV into pandas DataFrame
        download_url = join(download_url, '{0}/file'.format(file_id))
        requestDownload = requests.request("GET",
                                           download_url,
                                           headers=self.headers,
                                           stream=True)
        input_zip = zipfile.ZipFile(io.BytesIO(requestDownload.content))
        csv_filename = input_zip.namelist()[0]
        input_zip.extract(csv_filename)

        response_df = pd.read_csv(csv_filename)
        remove(csv_filename)

        return response_df
Ejemplo n.º 2
0
    def reserve_doi(self, article_id):
        """Reserve DOI if one has not been reserved"""

        url = self.endpoint(f"articles/{article_id}/reserve_doi",
                            institute=False)

        # Check if DOI has been reserved
        doi_check, doi_string = self.doi_check(article_id)

        if doi_check:
            print("DOI already reserved! Skipping... ")

            return doi_string
        else:
            print("DOI reservation has not occurred...")
            src_input = input(
                "Do you wish to reserve? Type 'Yes', otherwise this is skipped : "
            )
            if src_input == 'Yes':
                print("Reserving DOI ... ")
                response = issue_request('POST', url, self.headers)
                print(f"DOI minted : {response['doi']}")
                return response['doi']
            else:
                print("Skipping... ")
                return doi_string
Ejemplo n.º 3
0
    def get_groups(self):
        """Retrieve information about groups within institutional instance"""
        url = self.endpoint("groups")
        groups = issue_request('GET', url, self.headers)

        groups_df = pd.DataFrame(groups)
        return groups_df
Ejemplo n.º 4
0
    def list_surveys(self):
        """Return dictionary containing all surveys for a user"""

        url = self.endpoint('surveys')
        survey_dict = issue_request('GET', url, headers=self.headers)

        return survey_dict
Ejemplo n.º 5
0
    def get_curation_comments(self, curation_id):
        """Retrieve comments about specified curation item"""

        url = self.endpoint("review/{}/comments".format(curation_id))

        curation_comments = issue_request('GET', url, self.headers)

        return curation_comments
Ejemplo n.º 6
0
    def get_curation_details(self, curation_id):
        """Retrieve details about a specified curation item"""

        url = self.endpoint("review/{}".format(curation_id))

        curation_details = issue_request('GET', url, self.headers)

        return curation_details
Ejemplo n.º 7
0
    def get_user_projects(self, account_id):
        url = self.endpoint("projects", institute=False)

        # Figshare API is limited to a maximum of 1000 per page
        params = {'page': 1, 'page_size': 1000, 'impersonate': account_id}
        user_projects = issue_request('GET', url, self.headers, params=params)

        user_projects_df = pd.DataFrame(user_projects)
        return user_projects_df
Ejemplo n.º 8
0
    def get_articles(self):
        """Retrieve information about articles within institutional instance"""
        url = self.endpoint("articles")

        # Figshare API is limited to a maximum of 1000 per page
        params = {'page': 1, 'page_size': 1000}
        articles = issue_request('GET', url, self.headers, params=params)

        articles_df = pd.DataFrame(articles)
        return articles_df
Ejemplo n.º 9
0
    def doi_check(self, article_id):
        """Check if DOI is present/reserved"""
        url = self.endpoint(f"articles/{article_id}", institute=False)

        article_details = issue_request('GET', url, self.headers)

        check = False
        if article_details['doi']:
            check = True

        return check, article_details['doi']
Ejemplo n.º 10
0
    def get_account_list(self):
        """Retrieve accounts within institutional instance"""
        url = self.endpoint("accounts")

        # Figshare API is limited to a maximum of 1000 per page
        params = {'page': 1, 'page_size': 1000}
        accounts = issue_request('GET', url, self.headers, params=params)

        accounts_df = pd.DataFrame(accounts)
        accounts_df = accounts_df.drop(columns='institution_id')
        return accounts_df
Ejemplo n.º 11
0
    def get_curation_list(self, article_id=None):
        """Retrieve list of curation"""

        url = self.endpoint("reviews")

        params = {'offset': 0, 'limit': 1000}
        if not isinstance(article_id, type(None)):
            params['article_id'] = article_id

        curation_list = issue_request('GET', url, self.headers, params=params)

        curation_df = pd.DataFrame(curation_list)
        return curation_df
Ejemplo n.º 12
0
    def get_account_group_roles(self, account_id):
        """Retrieve group roles for a given account"""
        url = self.endpoint("roles/{}".format(account_id))

        roles = issue_request('GET', url, self.headers)
        return roles