Пример #1
0
def hastebin(text,
             url: str = 'https://hastebin.com'):
    try:
        post = requests.post(f'{url}/documents', data=text.encode('utf-8'))
        data = {'url': f'{url}/{post.json()["key"]}'}
        return data
    except Exception as e:
        logs.log(message=str(e), level='error')
    return None
Пример #2
0
 def upload_file(self, filePath, rename=False) -> bool:
     try:
         with open(filePath, 'rb') as f:
             logs.log(message=f"Uploading {filePath} to Dropbox...")
             if not rename:
                 filename = ntpath.basename(filePath)
             self.db.files_upload(f.read(),
                                  f'/{(rename if rename else filename)}',
                                  mode=dbx.files.WriteMode('overwrite'))
         return True
     except:
         pass
     return False
Пример #3
0
def get(url: str,
        params: dict = None,
        headers: dict = None,
        timeout: int = 2,
        log_level: str = None) -> Union[requests.Response, None]:
    if params:
        url += f"?{urlencode(params)}"
    try:
        res = requests.get(url=url, headers=headers, timeout=timeout)
        if log_level:
            logging.log(message=f"GET {url}", level=log_level)
            logging.log(message=f"Response: {res}",
                        level=("error" if not res else log_level))
        return res
    except requests.exceptions.Timeout:
        return None
Пример #4
0
def delete(url: str,
           params: dict = None,
           headers: dict = None,
           data: dict = None,
           timeout: int = 2,
           log_level: str = None) -> Union[requests.Response, None]:
    if params:
        url += f"?{urlencode(params)}"
    try:
        res = requests.delete(url=url,
                              json=data,
                              headers=headers,
                              timeout=timeout)
        if log_level:
            logging.log(message=f"DELETE {url}, Body: {data}", level=log_level)
            logging.log(message=f"Response: {res}",
                        level=("error" if not res else log_level))
        return res
        # use json= rather than data= to convert single-quoted dict to double-quoted JSON
    except requests.exceptions.Timeout:
        return None