From 8024375d3af3182207c7b0f46b0352feaf3e7494 Mon Sep 17 00:00:00 2001 From: Itz-fork Date: Tue, 13 Dec 2022 09:22:58 +0530 Subject: [PATCH] v1.4.3 - Fixed upload_folder function --- .gitignore | 1 + gofile2/__init__.py | 2 +- gofile2/async_gofile2.py | 12 +++++++++++- gofile2/gofile2.py | 11 ++++++++++- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 44eb403..b35e207 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ dist +build gofile2.egg-info \ No newline at end of file diff --git a/gofile2/__init__.py b/gofile2/__init__.py index 1a5678e..f2f1a1d 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.4.2" \ No newline at end of file +__version__ = "v1.4.3" \ No newline at end of file diff --git a/gofile2/async_gofile2.py b/gofile2/async_gofile2.py index fa5b680..7e45f39 100644 --- a/gofile2/async_gofile2.py +++ b/gofile2/async_gofile2.py @@ -3,6 +3,8 @@ # Project: Gofile2 import os +from asyncio import sleep +from time import strftime from aiohttp import ClientSession from .errors import (InvalidOption, InvalidPath, InvalidToken, JobFailed, ResponseError, is_valid_token) @@ -85,8 +87,10 @@ async def get_Account(self, check_account=False): except Exception as e: raise JobFailed(e) - async def upload_folder(self, path: str, folderId: str = ""): + async def upload_folder(self, path: str, folderId: str = "", folder_name: str = "Gofile2", delay: int = 2): """ + NOTE: To use this function, you must have a gofile token + ### Upload folder Function Upload files in the given path to Gofile @@ -95,15 +99,21 @@ async def upload_folder(self, path: str, folderId: str = ""): - `path` - Path to the folder - `folderId` (optional) - The ID of a folder. When using the folderId, you must pass the token + - `delay` - Time interval between file uploads (in seconds) """ if not os.path.isdir(path): raise InvalidPath(f"{path} is not a valid directory") uploaded = [] files = [val for sublist in [[os.path.join( i[0], j) for j in i[2]] for i in os.walk(path)] for val in sublist] + # Get folder id if not passed + if not folderId: + rtfid = (await self.get_Account())["rootFolder"] + folderId = (await self.create_folder(rtfid, "Gofile2 - Created in {}".format(strftime("%b %d, %Y %l:%M%p"))))["id"] for file in files: udt = await self.upload(file, folderId) uploaded.append(udt) + await sleep(2) return uploaded async def upload(self, file: str, folderId: str = "", description: str = "", password: str = "", tags: str = "", expire: str = ""): diff --git a/gofile2/gofile2.py b/gofile2/gofile2.py index 8f904be..6fa2c27 100644 --- a/gofile2/gofile2.py +++ b/gofile2/gofile2.py @@ -3,6 +3,7 @@ # Project: Gofile2 import os +from time import time, strftime from requests import delete, get, post, put from .errors import (InvalidOption, InvalidPath, InvalidToken, JobFailed, ResponseError, is_valid_token) @@ -81,8 +82,10 @@ def get_Account(self, check_account=False): raise JobFailed( f"Error Happend: {e} \n\nReport this at ----> https://github.com/Itz-fork/Gofile2/issues") - def upload_folder(self, path: str, folderId: str = ""): + def upload_folder(self, path: str, folderId: str = "", delay: int = 2): """ + NOTE: To use this function, you must have a gofile token + ### Upload folder Function Upload files in the given path to Gofile @@ -91,15 +94,21 @@ def upload_folder(self, path: str, folderId: str = ""): - `path` - Path to the folder - `folderId` (optional) - The ID of a folder. When using the folderId, you must pass the token + - `delay` - Time interval between file uploads (in seconds) """ if not os.path.isdir(path): raise InvalidPath(f"{path} is not a valid directory") uploaded = [] files = [val for sublist in [[os.path.join( i[0], j) for j in i[2]] for i in os.walk(path)] for val in sublist] + # Get folder id if not passed + if not folderId: + rtfid = self.get_Account()["rootFolder"] + folderId = self.create_folder(rtfid, "Gofile2 - Created in {}".format(strftime("%b %d, %Y %l:%M%p")))["id"] for file in files: udt = self.upload(file, folderId) uploaded.append(udt) + time.sleep(2) return uploaded def upload(self, file: str, folderId: str = None, description: str = None, password: str = None, tags: str = None, expire: int = None):