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 simple program to display current playing from Spotify app on your desktop

WallSpot A simple program to display current playing from Spotify app on your desktop How to Use: Linux: Currently Supports GNOME and KDE. If you want

Nannan 4 Feb 19, 2022
Telegram bot that search for the classrooms status of the chosen day and then return all the free classrooms using your preferred time slot

Aule Libere Polimi Since the PoliMi site no longer allows people to search for free classrooms this bot was necessary! It simply search for the classr

Daniele Ferrazzo 16 Nov 09, 2022
A comand-line utility for taking automated screenshots of websites

shot-scraper A comand-line utility for taking automated screenshots of websites For background on this project see shot-scraper: automated screenshots

Simon Willison 837 Jan 07, 2023
Send embeds using your discord personal account

Welcome to Embed Sender 👋 Send embeds using your discord personal account Install pip install -r requirements.txt Usage Put your discord token in ./

SkydenFly 11 Sep 07, 2022
This project is a basic login system in terminal for Discord

Welcome to Discord Login System(Terminal) 👋 This project is a basic login system in terminal for Discord Author 👤 arukovic Github: @SONIC-CODEZ Show

SONIC-CODEZ 2 Feb 11, 2022
A new coin listing alert bot using Python, Flask, MongoDB, Telegram API and Binance API

Bzzmans New Coin Listing Detection Bot Architecture About Project Work in progress. This bot basically gets new coin listings from Binance using Binan

Eyüp Barlas 21 May 31, 2022
Auslesen, entschlüsseln und parsen von Smart Meter Telegrammen

Netz-NÖ SmartMeter-P1-Reader https://www.netz-noe.at/Download-(1)/Smart-Meter/218_9_SmartMeter_Kundenschnittstelle_lektoriert_14.aspx Dieses Skript en

3 Jan 14, 2022
A simple discord bot that generates facts!

fact-bot A simple discord bot that generates facts! How to make a bot Go to https://discord.com/developers/applications Then click on 'New Application

1 Jan 05, 2022
ВКонтакте бот для управления Sugar кошельком

Sugarchain VK ВКонтакте бот для управления Sugar кошельком Установка Установить зависимости можно командой: pip install -r requirements.txt Запуск (из

Vladimir 4 Jun 06, 2021
This package allows interactions with the BuyCoins API.

The BuyCoins Python library allows interactions with the BuyCoins API from applications written in Python.

Abdulazeez Abdulazeez Adeshina 45 May 23, 2022
A Telegram bot that add a dynamic caption to musics

Music Channel Manager A Telegram bot that add a dynamic caption to musics Deploy to Heroku What is it ? It manage your music channel. With just adding

13 Oct 18, 2022
Python3 script to dump employee information from XING API

XingDumper Python 3 script to dump company employees from XING API. Perfect OSINT tool ;-) The results contain firstname, lastname, position, gender,

LRVT 11 Dec 26, 2022
List of twitch bots n bigots

This is a collection of bot account names NamelistMASTER contains all the names we reccomend you ban in your channel Sometimes people get on that list

62 Sep 05, 2021
Asynchronous wrapper для Gismeteo.ru.

aiopygismeteo Асинхронная обёртка для Gismeteo.ru. Синхронная версия здесь. Установка python -m pip install -U aiopygismeteo Документация https://aiop

Almaz 6 Dec 08, 2022
Модуль для создания скриптов для ВКонтакте | vk.com API wrapper

vk_api vk_api – Python модуль для создания скриптов для ВКонтакте (vk.com API wrapper) Документация Примеры Чат в Telegram Документация по методам API

Kirill 1.2k Jan 04, 2023
GitGram Bot. Bot Then Message You Your Repo Starts, Forks, And Many More

Yet Another GitAlertBot Inspired From Dev-v2's GitGram Run Bot: Local Host Git Clone Repo : For Telethon Version : git clone https://github.com/TeamAl

Alina RoBot 2 Nov 24, 2021
Network simulation tools

Overview I'm building my network simulation environments with Vagrant using libvirt plugin on a Ubuntu 20.04 system... and I always hated how boring i

Ivan Pepelnjak 219 Jan 07, 2023
A Multi-Tool with 30+Options.

A Multi-Tool with 30+Options.

Mervin404 15 Apr 12, 2022
Discord bot that performs various functions.

rikka-bot A Discord bot that performs various functions. Table of Contents Commands Main Commands Utility Commands Admin Commands Self-Assignable Role

Carlos Saucedo 7 Aug 27, 2021
A Telegram Video Merge Bot by @AbirHasan2005

VideoMerge-Bot This is very simple Telegram Videos Merge Bot by @AbirHasan2005. Using FFmpeg for Merging Videos. Features: Merge Multiple Videos. User

Abir Hasan 57 Nov 12, 2022