From 2791192b0172aeb0eaebf8460d30aaccd1b6cd5e Mon Sep 17 00:00:00 2001 From: Itz-fork Date: Thu, 9 Dec 2021 09:33:48 +0530 Subject: [PATCH] Update v1.3.6 - Added api methods of 2021-11-17 update --- README.md | 8 ++++- gofile2/__init__.py | 2 +- gofile2/async_gofile2.py | 44 +++++++++++++++++++++++++++ gofile2/gofile2.py | 42 ++++++++++++++++++++++++++ setup.py | 64 ++++++++++++++++++++-------------------- 5 files changed, 126 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 613c195..5cf5fe9 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ print(g_a.upload(file="/home/itz-fork/photo.png")) # About API > Gofile is in BETA version and this API will evolve over time. Check regularly if changes have been made. > -Current version is compatible with `2021-06-22` +Current version is compatible with `2021-11-17` # Installation Install via pypi @@ -73,6 +73,12 @@ g_a.create_folder(parentFolderId="your_root_folder_id", folderName="Folder Name" # Set folder options g_a.set_folder_options(folderId="id_of_the_folder", option="your_option", value="your_value") +# Get content details +g_a.get_content(contentId="id_of_the_file_or_folder") + +# Copy file or folder to another folder +g_a.copy_content(contentId="id_of_the_file_or_folder", folderIdDest="id_of_the_destination_folder") + # Delete file or folder g_a.delete_content(contentId="id_of_the_file_or_folder") ``` diff --git a/gofile2/__init__.py b/gofile2/__init__.py index cbbe3b9..bb89a66 100644 --- a/gofile2/__init__.py +++ b/gofile2/__init__.py @@ -5,4 +5,4 @@ from .gofile2 import Gofile from .async_gofile2 import Async_Gofile -__version__ = "v1.3.5" +__version__ = "v1.3.6" diff --git a/gofile2/async_gofile2.py b/gofile2/async_gofile2.py index 2f7ea57..4fd53b5 100644 --- a/gofile2/async_gofile2.py +++ b/gofile2/async_gofile2.py @@ -192,6 +192,50 @@ async def set_folder_options(self, folderId, option, value): return await self._api_resp_handler(set_folder_resp) except Exception as e: raise JobFailed(f"Error Happend: {e} \n\nReport this at ----> https://github.com/Itz-fork/Gofile2/issues") + + async def get_content(self, contentId): + """ + Get Content Function: + Get a specific content details + + Arguments: + contentId - The ID of the file or folder + """ + if self.token is None: + raise InvalidToken("Token is required for this action but it's None") + async with self.r_session as session: + try: + get_content_resp = await session.get(url=f"{self.api_url}getContent?contentId={contentId}&token={self.token}") + get_content_resp = await get_content_resp.json() + return await self._api_resp_handler(get_content_resp) + except Exception as e: + raise JobFailed(f"Error Happend: {e} \n\nReport this at ----> https://github.com/Itz-fork/Gofile2/issues") + + async def copy_content(self, contentsId, folderIdDest): + """ + Copy Content Function: + Copy one or multiple contents to another folder + + Arguments: + contentsId - The ID(s) of the file or folder (Separate each one by comma if there are multiple IDs) + folderIdDest - Destinatination folder ID + """ + if self.token is None: + raise InvalidToken("Token is required for this action but it's None") + async with self.r_session as session: + try: + copy_content_resp = await session.put( + url=f"{self.api_url}copyContent", + data={ + "token": self.token, + "contentsId": contentsId, + "folderIdDest": folderIdDest + } + ) + copy_content_resp = await copy_content_resp.json() + return await self._api_resp_handler(copy_content_resp) + except Exception as e: + raise JobFailed(f"Error Happend: {e} \n\nReport this at ----> https://github.com/Itz-fork/Gofile2/issues") async def delete_content(self, contentId): """ diff --git a/gofile2/gofile2.py b/gofile2/gofile2.py index 5a33a79..95a9dfa 100644 --- a/gofile2/gofile2.py +++ b/gofile2/gofile2.py @@ -168,6 +168,48 @@ def set_folder_options(self, folderId, option, value): except Exception as e: raise JobFailed(f"Error Happend: {e} \n\nReport this at ----> https://github.com/Itz-fork/Gofile2/issues") + def get_content(self, contentId): + """ + Get Content Function: + Get a specific content details + + Arguments: + contentId - The ID of the file or folder + """ + token = self.token + if token is None: + raise InvalidToken("Token is required for this action but it's None") + try: + get_content_resp = requests.get(url=f"{self.api_url}getContent?contentId={contentId}&token={token}").json() + return self._api_resp_handler(get_content_resp) + except Exception as e: + raise JobFailed(f"Error Happend: {e} \n\nReport this at ----> https://github.com/Itz-fork/Gofile2/issues") + + def copy_content(self, contentsId, folderIdDest): + """ + Copy Content Function: + Copy one or multiple contents to another folder + + Arguments: + contentsId - The ID(s) of the file or folder (Separate each one by comma if there are multiple IDs) + folderIdDest - Destinatination folder ID + """ + token = self.token + if token is None: + raise InvalidToken("Token is required for this action but it's None") + try: + copy_content_resp = requests.put( + url=f"{self.api_url}copyContent", + data={ + "token": token, + "contentsId": contentsId, + "folderIdDest": folderIdDest + } + ).json() + return self._api_resp_handler(copy_content_resp) + except Exception as e: + raise JobFailed(f"Error Happend: {e} \n\nReport this at ----> https://github.com/Itz-fork/Gofile2/issues") + def delete_content(self, contentId): """ Delete Content Function: diff --git a/setup.py b/setup.py index 882872c..a486129 100644 --- a/setup.py +++ b/setup.py @@ -8,43 +8,43 @@ os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))) if os.path.isfile('requirements.txt'): - with open('requirements.txt') as req: - reques = req.read().splitlines() + with open('requirements.txt') as req: + reques = req.read().splitlines() else: - reques = [ - 'requests', - 'aiohttp', - 'fake-useragent' - ] + reques = [ + 'requests', + 'aiohttp', + 'fake-useragent' + ] if os.path.isfile('README.md'): - with open(('README.md'), encoding='utf-8') as readmeh: - big_description = readmeh.read() + with open(('README.md'), encoding='utf-8') as readmeh: + big_description = readmeh.read() else: - big_description = "Gofile2 is an API wrapper for Gofile API" + big_description = "Gofile2 is an API wrapper for Gofile API" # Version -v = "v1.3.5" +v = "v1.3.6" setup(name='gofile2', -version=v, -description='An API wrapper for Gofile API', -url='https://github.com/Itz-fork/Gofile2', -author='Itz-fork, Codec04', -author_email='itz-fork@users.noreply.github.com', -license='MIT', -packages=find_packages(), -download_url=f"https://github.com/Itz-fork/Gofile2/releases/tag/Gofile2-{v}", -keywords=['Gofile', 'Api-wrapper', 'Gofile2'], -long_description=big_description, -long_description_content_type='text/markdown', -install_requires=reques, -classifiers=[ - 'Development Status :: 5 - Production/Stable', - 'Intended Audience :: Developers', - 'Topic :: Education', - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.9', - ], -) + version=v, + description='An API wrapper for Gofile API', + url='https://github.com/Itz-fork/Gofile2', + author='Itz-fork, Codec04', + author_email='itz-fork@users.noreply.github.com', + license='MIT', + packages=find_packages(), + download_url=f"https://github.com/Itz-fork/Gofile2/releases/tag/Gofile2-{v}", + keywords=['Gofile', 'Api-wrapper', 'Gofile2'], + long_description=big_description, + long_description_content_type='text/markdown', + install_requires=reques, + classifiers=[ + 'Development Status :: 5 - Production/Stable', + 'Intended Audience :: Developers', + 'Topic :: Education', + 'License :: OSI Approved :: MIT License', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.9', + ], + )