mirror of
https://github.com/NohamR/gofilepy.git
synced 2026-01-11 08:48:16 +00:00
fix: .env working
This commit is contained in:
63
README.md
63
README.md
@@ -75,25 +75,56 @@ gofilepy -vv big_file.iso
|
||||
You can use `gofilepy` in your own Python scripts.
|
||||
|
||||
```python
|
||||
import os
|
||||
from gofilepy import GofileClient
|
||||
from tqdm import tqdm
|
||||
|
||||
# Initialize (Token optional for guest upload)
|
||||
client = GofileClient(token="your_token")
|
||||
TOKEN = os.environ.get("GOFILE_TOKEN") # in .env file, or put it here
|
||||
FILES_TO_UPLOAD = [
|
||||
"/path/to/video1.mp4",
|
||||
"/path/to/image.jpg"
|
||||
]
|
||||
FOLDER_ID = None # None to create new folder, or put folder ID here
|
||||
|
||||
# Simple Callback for progress
|
||||
def my_progress(bytes_read):
|
||||
print(f"Read: {bytes_read} bytes")
|
||||
def upload_files():
|
||||
client = GofileClient(token=TOKEN)
|
||||
|
||||
print(f"Starting upload... {len(FILES_TO_UPLOAD)}")
|
||||
|
||||
# Upload (Streaming)
|
||||
try:
|
||||
response = client.upload_file(
|
||||
file_path="/path/to/movie.mkv",
|
||||
folder_id=None, # None = Create new folder
|
||||
callback=my_progress
|
||||
)
|
||||
print(f"Uploaded! Download here: {response['downloadPage']}")
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
for file_path in FILES_TO_UPLOAD:
|
||||
if not os.path.exists(file_path):
|
||||
print(f"❌ File not found: {file_path}")
|
||||
continue
|
||||
|
||||
filename = os.path.basename(file_path)
|
||||
filesize = os.path.getsize(file_path)
|
||||
|
||||
with tqdm(total=filesize, unit='B', unit_scale=True, desc=filename) as pbar:
|
||||
|
||||
def progress_callback(bytes_read):
|
||||
uploaded_so_far = pbar.n
|
||||
pbar.update(bytes_read - uploaded_so_far)
|
||||
|
||||
try:
|
||||
response = client.upload_file(
|
||||
file_path=file_path,
|
||||
folder_id=FOLDER_ID,
|
||||
callback=progress_callback
|
||||
)
|
||||
|
||||
global FOLDER_ID
|
||||
if FOLDER_ID is None and 'parentFolder' in response:
|
||||
FOLDER_ID = response['parentFolder']
|
||||
|
||||
pbar.update(filesize - pbar.n)
|
||||
|
||||
tqdm.write(f"✅ Success : {response.get('downloadPage')}")
|
||||
|
||||
except Exception as e:
|
||||
tqdm.write(f"❌ Error, {filename}: {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
upload_files()
|
||||
```
|
||||
|
||||
## Building for Release
|
||||
@@ -102,7 +133,7 @@ To build a `.whl` (Wheel) file and a source distribution:
|
||||
|
||||
1. Install build tools:
|
||||
```bash
|
||||
pip install build twine
|
||||
pip install build
|
||||
```
|
||||
2. Run build:
|
||||
```bash
|
||||
|
||||
Reference in New Issue
Block a user