Gdrive-python: A wrapping module in python of gdrive

Overview

gdrive-python

gdrive-python is a wrapping module in python of gdrive made by @prasmussen.

Installation

First of all to install the package you can execute:

pip install gdrive-python

Than you have to login inside your Google account with the command and than follow the instructions:

python -m gdrive about [options]

options:
  --version     Version of the gdrive script to download
  --os-name     Operating system name, by default it gets current os. Options: ['windows', 'linux', 'darwin']
  --arch        Architecture. Options: ['amd64', '386']
  --url         Url of the gdrive script

Example output:

vpippi$ python -m gdrive about
CMD: gdrive_folder/gdrive --config gdrive_folder about
Authentication needed
Go to the following url in your browser:
https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=############.apps.googleusercontent.com&redirect_uri=#########&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&state=state

Enter verification code:
# paste here the code and press enter

FileNotFoundError

Somethimes it can happen that the command python -m gdrive about returns the FileNotFoundError

vpippi$ python -m gdrive about
CMD: gdrive_folder/gdrive --config gdrive_folder about
Traceback (most recent call last):
  ...
FileNotFoundError: [Errno 2] No such file or directory: 'gdrive_folder/gdrive'

In my case it happened because the current system architecture is amd64 but this version don't works in that system. You can avoid that problem by installing the 386 architecture.

python -m gdrive about --arch 386

Usage

import the gdrive classes in that way:

form gdrive import GDrive, GDrivePath, GDriveThread

GDrive

drive = GDrive()

If you whant you can also enable the printing commands setting:

drive.print_output = True

__init__(self, gdrive_path=None)

  • gdrive_path defines the gdrive script location path. If not specified it gets the default location gdrive_folder/gdrive

@staticmethod download_script(version='2.1.1', os_name=None, arch=None, url=None)

  • version is the version of the gdrive script to download
  • os_name is the operating system name, by default it gets current os. Options: ['windows', 'linux', 'darwin']
  • arch is the architecture. Options: ['amd64', '386']
  • url is the url of the gdrive script. If an url is provided the other fields are ignored.

The script download the specified version in the current directory (eg. gdrive_2.1.1_windows_amd64.tar.gz) and than extract the archive inside the directory gdrive_folder.

Returns None.

upload(self, filename, parent_id=None, parent=None, recursive=True, name=None, description=None, mime=None, share=None, timeout=None, chunksize=None, delete=False, thread=False)

  • filename path of the file/folder to upload
  • parent parent directory by name (eg. /path/foldername)
  • parent_id parent id, used to upload file to a specific directory, if specified parent folder is ignored.
  • recursive upload directory recursively
  • name filename
  • description file description
  • mime force mime type
  • share share file
  • timeout set timeout in seconds, use 0 for no timeout. Timeout is reached when no data is transferred in set amount of seconds, default: 300
  • chunksize set chunk size in bytes, default: 8388608
  • delete delete local file when upload is successful
  • thread defines if you want to upload the file in a separate thread (see the thread section)

While uploading a large file could be useful set print_output = True

Example:

>>> drive.print_output = True
>>> drive.upload('File99.mp4')
CMD: gdrive_folder\gdrive.exe --config gdrive_folder upload --recursive checkpoint_042.pth
Uploading checkpoint_042.pth
1.1 GB / 2.0 GB, Rate: 13.7 MB/s

thread

When thead=True the methods return a GDriveThread(threading.Thread) object.

Usage:

>>> thread = drive.upload('File99.mp4', thread=True)
>>> thread.start()
>>> # do whatever you want
>>> thread.join()

about(self)

Returns a dictionary that shows the account info.

Example:

>>> drive.about()
{
    'User': 'name username, [email protected]',
    'Used': '51 GB',
    'Free': '9 GB',
    'Total': '60 GB',
    'Max upload size': '60 GB',
}

logout(self)

The logout function delete the file gdrive_folder/token_v2.json which contains the google info. After this command the login is required again (see installation procedure).

list(self, max=30, querys=[], sort_order=None, name_width=0, absolute=False, bytes=None, parent=None)

Returns a list of dictionaries. Example:

>>> drive.list()
[
    {'Id': '######', 'Name': 'File01.mp4', 'Type': 'bin', 'Size': '196.1 MB', 'Created': '2022-01-13 19:42:00'},
    {'Id': '######', 'Name': 'File02.mp4', 'Type': 'bin', 'Size': '210.7 MB', 'Created': '2022-01-13 19:42:00'},
    {'Id': '######', 'Name': 'File03.mp4', 'Type': 'bin', 'Size': '197.5 MB', 'Created': '2022-01-13 19:42:00'},
    {'Id': '######', 'Name': 'File04.mp4', 'Type': 'bin', 'Size': '191.5 MB', 'Created': '2022-01-13 19:42:00'},
    {'Id': '######', 'Name': 'File05.mp4', 'Type': 'bin', 'Size': '176.1 MB', 'Created': '2022-01-13 19:42:00'},
    {'Id': '######', 'Name': 'File06.mp4', 'Type': 'bin', 'Size': '178.0 MB', 'Created': '2022-01-13 19:42:00'},
    ...
]

list_dirs(self, *args, **kwargs)

Same parameters as the list method.

Returns only the a list of dirs.

list_files(self, *args, **kwargs)

Same parameters as the list method.

Returns only the a list of files.

get_id(self, name)

  • name name of the file/folder that you want the id

Since Google Drive allows different files/directories with the same name, the function returns:

  • string if only one element is found
  • list of the ids if more than one file is returned
  • None if only no one element is found

Example:

>>> drive.get_id('File01.mp4')
'BWoSkGeDNbYqyumaRXtQvzgHndUMET'

>>> drive.get_id('File00.mp4')
['BWoSkGeDNbYqyumaRXtQvzgHndUMET', 'vzgHndUMETscKflCxpVOwhjrAiPLFI']

>>> drive.get_id('File99.mp4')
None

info(self, id)

  • id id of the file/folder

Returns a dictionary of all info values of the given element.

Owner
Vittorio Pippi
Vittorio Pippi
A Happy and lightweight Python Package that Provides an API to search for articles on Google News and returns a JSON response.

A Happy and lightweight Python Package that Provides an API to search for articles on Google News and returns a JSON response.

Muhammad Abdullah 273 Dec 31, 2022
The WhatsApp lib

yowsup WARNING It seems that recently yowsup gets detected during registration resulting in an instant ban for your number right after registering wit

Tarek 6.8k Jan 04, 2023
A VCVideoPlayer Bot for Telegram made with 💞 By @TeamDeeCoDe

VC Video Player How To Host ✨ Heroku Deploy ✨ The easiest way to deploy this Bot is via Heroku. Credit 🔥 |🇮🇳 Louis |🇮🇳 Sammy |🇮🇳 Blaze |🇮🇳 S

TeamDeeCode 6 Feb 28, 2022
SmartFile API Client (Python).

A SmartFile Open Source project. Read more about how SmartFile uses and contributes to Open Source software. Summary This library includes two API cli

SmartFile 19 Jan 11, 2022
Get informed when your DeFI Earn CRO Validator is jailed or changes the commission rate.

CRO-DeFi-Warner Intro CRO-DeFi-Warner can be used to notify you when a validator changes the commission rate or gets jailed. It can also notify you wh

5 May 16, 2022
Use Seaborn to visualize interpret the byte layout of Solana account types

solana-account-vis Use Seaborn to visually interpret the byte layout of Solana account types Usage from account_visualization import generate_account_

Jarry Xiao 15 Aug 25, 2022
A very basic starter bot based on CryptoKKing with a small balance

starterbot A very basic starter bot based on CryptoKKing with a small balance, use at your own risk. I have since upgraded this script significantly a

Danny Kendrick 2 Dec 05, 2021
A Telegram Repo For Devs To Controll The Bots Under Maintenance.This Bot Is For Developers, If Your Bot Is Down, Use This Repo To Give Your Dear Subscribers Some Support By Providing Them Response.

Maintenance Bot A Telegram Repo For Devs To Controll The Bots Under Maintenance About This Bot This Bot Is For Developers, If Your Bot Is Down, Use Th

Vɪᴠᴇᴋ 47 Dec 29, 2022
A simple Discord bot that notifies users of new Abitti versions

A simple Discord bot that notifies users of new Abitti versions. New features might be added later on. If you have good ideas, feel free to do a PR.

1 Feb 11, 2022
this repo store a Awoesome telegram bot for protect from your large group from bot attack.

this repo store a Awoesome telegram bot for protect from your large group from bot attack.

Mehran Alam Beigi 2 Jul 22, 2022
Design and build a wrapper for the Open Weather API current weather data service

Design and build a wrapper for the Open Weather API current weather data service that returns a city's temperature, with caching, also allowing for the temperature of the latest queried cities that a

Duan Rafael Ribeiro 1 Jun 27, 2022
Search twitter by address.

Twitter Geolocate Twitter Geolocation is a console app that generates twitter search querries for a certain geolocation and opens them in your standar

David J. Kowalk 28 Dec 06, 2022
A Bot that Forwards Tweets to Telegram using Airtable as a database.

Twitter Telegram Forward A Bot that Forwards Tweets to Telegram using Airtable as a Database. Features: Handles multiple twitter and telegram channels

George Bakev 3 Dec 21, 2022
A tool to build scripts to toggle between minimal & default services in Windows based on user defined lists.

A tool to build scripts to toggle between minimal & default services in Windows based on user defined lists.

AMIT 29 Jan 01, 2023
This project checks the weather in the next 12 hours and sends an SMS to your phone number if it's going to rain to remind you to take your umbrella.

RainAlert-Request-Twilio This project checks the weather in the next 12 hours and sends an SMS to your phone number if it's going to rain to remind yo

9 Apr 15, 2022
Telegram 聊天機器人,追蹤momo降價、重新上架

簡介 price-tracker-bot is a telegram bot that can trace the price on momoshop. 功能 降價通知 上架通知 收藏商品 清空已收藏商品 顯示目前已收藏商品 Demo Bot Telegram bot search @momo_pr

92 Dec 28, 2022
Translates English into Mandalorian (Mando'a) utilizing a "funtranslations" free API

Mandalorian Translator Translates English into Mandalorian (Mando'a) utilizing a "funtranslations" free API About I created this app to experiment wit

Hayden Covington 1 Dec 04, 2021
discord token grabber using python

Discord Token Grabber A Discord token grabber written in Python 3. This version of the grabber only supports Windows. Features No local caching Transf

1 Oct 28, 2021
SpaceManJax's open-source Discord Bot. Now on Github!

SpaceManBot This is SpaceManJax's open-source Discord.py Bot. Now on Github! This bot runs on Repl.it, which is a free online code editor. It can do a

Jack 1 Nov 16, 2021
The official Magenta Voice Skill SDK used to develop skills for the Magenta Voice Assistant using Voice Platform!

Magenta Voice Skill SDK Development • Support • Contribute • Contributors • Licensing Magenta Voice Skill SDK for Python is a package that assists in

Telekom Open Source Software 18 Nov 19, 2022