gdnan
A Google Drive API wrapper written in python by @viperadnan with ♥️.
Project's Base
The base of the project taken from lzzy12's repo python-aria-mirror-bot and modified, improved and compiled in a pip package.
Installing
Install using pip
pip3 install gdnan
Usage
from gdnan import GoogleDrive, Auth, extractId, create_link
GooogleDriveClientID = "9999199991-128shwbnwinpcqv6hn7b29wuww4gmji.apps.googleusercontent.com"
GooogleDriveClientSecret = "2lhkFmsQ0W7wJaua72HwodjZ"
auth = Auth(GooogleDriveClientID, GooogleDriveClientSecret)
print("Open this url in browser and enter the received code")
print(auth.get_url())
received_code = input("Enter received code: ")
credentials = auth.exchange_code(received_code)
auth.exchange_code(received_code, "token.pickle")
gd = GoogleDrive(credentials)
workdir_id = extractId("https://drive.google.com/folderview?id=1Aricl6VpSiMmgFkgUSeTXiQh7WYxW6np")
gd = GoogleDrive("token.pickle", workdir_id)
uploaded_file = gd.upload("path/to/file/or/folder/example.txt")
uploaded_file = gd.upload("path/to/file/or/folder/example.txt", "root")
print(uploaded_file.name)
>> example.txt
print(uploaded_file.url)
>> https://drive.google.com/uc?id=10xN4KBjKJXUwIHUv1R5rihbthYuENMUB&export=download
print(create_link(uploaded_file.id, uploaded_file.mimeType))
>> https://drive.google.com/uc?id=10xN4KBjKJXUwIHUv1R5rihbthYuENMUB&export=download
folder = gd.create_folder("Hello World!", workdir_id)
print(folder.name)
>> Hello World!
cloned_file = gd.clone(uploaded_file.id)
print(cloned_file.name)
>> example.txt
gd.move(cloned_file.id, folder.id)
gd.make_public(cloned_file.id)
files, next_page_token = gd.search(uploaded_file.name, limit=2, folder=workdir_id)
for file in files:
print(file.name)
>> example.txt
gd.delete(uploaded_file.id)
gd.delete(folder.id, True)
gd.emptyTrash()
Using Service Accounts
If you want to use service accounts than put a copy of all of your service accounts in a folder and use code below
from gdnan import GoogleDrive
gd = GoogleDrive("path/to/service/account/folder", workdir_id)
this will automatically rename your service accounts to 0.json 1.json 2.json...
(if not renamed) and automatically switch between service accounts if daily quota exceeded.
Testing
Test code by running test.py in your terminal with python3 test.py
, don't forget to change the GooogleDriveClientID and GooogleDriveClientSecret.
Copyright & License