Exemplo n.º 1
0
 def __init__(self):
     self.file = ""
     self.pid = ""
     self.token = ""
     self.attachment = {}
     apix = api.Api()
     self.api = apix.api
Exemplo n.º 2
0
 def login(self):
     """login and return token"""
     credentials = {}
     self.get_username()
     credentials["username"] = self.username
     password = keyring.get_password('scicat', self.username)
     if not password:
         print("No password found in keychain, please enter it now to store it.")
         password = getpass.getpass()
         keyring.set_password('scicat', self.username, password)
     credentials["password"] = password
     apix = api.Api()
     url = os.path.join(apix.base, "auth/msad")
     token = ""
     response = requests.post(url, json=credentials)
     result = response.json()
     # print(result)
     token = ""
     if response.status_code == 200:
         pass
     else:
         print("Login failed")
         print(response.status_code)
         return token
     if isinstance(result, str):
         pass
         # print("token", token)
     else:
         token = result.get("access_token")
         # print("token", token)
     self.token = token
     return token
Exemplo n.º 3
0
 def __init__(self):
     apix = api.Api()
     self.api = apix.api
     loginx = LoginManager()
     userinfo = loginx.info()
     self.email = userinfo["currentUserEmail"]
     self.owner = userinfo["currentUser"]
     groups = userinfo["currentGroups"]
     self.owner_group = groups[0]
Exemplo n.º 4
0
 def info(self):
     """get info"""
     if self.token == "":
         self.login()
     apix = api.Api()
     url = apix.api + "Users/userInfos?access_token=" + self.token
     response = requests.get(url)
     requests.get(url)
     info = response.json()
     return info
Exemplo n.º 5
0
def search(text, limit=10):
    """search scicat"""
    fields = {'text': text}
    limits = {'limit': limit, 'order': "creationTime:desc"}
    fields_encode = urllib.parse.quote(json.dumps(fields))
    limit_encode = urllib.parse.quote(json.dumps(limits))
    apix = api.Api()
    dataset_url = os.path.join(apix.api, "Datasets/anonymousquery?fields=") + \
        fields_encode+"&limits="+limit_encode
    response = requests.get(dataset_url).json()
    print(len(response), "result found!")
    return response
Exemplo n.º 6
0
    def __init__(self,
                 username: str = None,
                 password: str = None,
                 timeout: int = 0.25):
        """
        Create a SciCat instance and obtain a login token.

        :param username: SciCat username
        :param password: SciCat password
        :param timeout: Timeout when obtaining files.
        """
        self.username = username
        self.token = None
        self.timeout = timeout
        self.bigtimeout = datetime.timedelta(seconds=60)
        self.scicat = api.Api()
        self.token = self.get_token(password)