Skip to content

Commit

Permalink
v1.4.3 - Fixed upload_folder function
Browse files Browse the repository at this point in the history
  • Loading branch information
Itz-fork committed Dec 13, 2022
1 parent 7136d1c commit 8024375
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dist
build
gofile2.egg-info
2 changes: 1 addition & 1 deletion gofile2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
from .gofile2 import Gofile
from .async_gofile2 import Async_Gofile

__version__ = "v1.4.2"
__version__ = "v1.4.3"
12 changes: 11 additions & 1 deletion gofile2/async_gofile2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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 = ""):
Expand Down
11 changes: 10 additions & 1 deletion gofile2/gofile2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down

0 comments on commit 8024375

Please sign in to comment.