Created
August 24, 2022 16:40
-
-
Save pthavarasa/8a9206045435b69c232dda3606dfebe5 to your computer and use it in GitHub Desktop.
upload files to mega.nz using python (single file, directory, by extension)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mega import Mega | |
import os | |
class UploadMega(): | |
def __init__(self, id, password): | |
mega = Mega() | |
self.mega = mega.login(id, password) | |
def upload_single_file(self, path): | |
print("uploading :", path) | |
self.mega.upload(path) | |
print("uploaded :", path) | |
def upload_directory(self, path): | |
files = os.listdir(path) | |
for i in files: | |
print("uploading :", i) | |
self.mega.upload(os.path.join(path, i)) | |
print("uploaded :", i) | |
def upload_files_by_extension(self, path, extension): | |
files = os.listdir(path) | |
for i in files: | |
if i.split(".")[-1] == extension: | |
print("uploading :", i) | |
self.mega.upload(os.path.join(path, i)) | |
print("uploaded :", i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment