Skip to content

Instantly share code, notes, and snippets.

@aaronmauro
Created January 29, 2020 17:24
Show Gist options
  • Save aaronmauro/2a422902a3adb8f5882341191e8aa3ca to your computer and use it in GitHub Desktop.
Save aaronmauro/2a422902a3adb8f5882341191e8aa3ca to your computer and use it in GitHub Desktop.
Deletes all content on Google Drive and uploads custom message
#!/usr/bin/python3
#pip install PyDrive
"""
Warning: This software is for research and educational purposes only.
Please do not violate any local or international laws. Please do not break terms of service with other entities.
Please read and understand the code before using it.
This code deletes all content from Google Drive and replaces it with a custom message for Google's algorithms to process.
You can control the size and content of this message by modifying two variables below!
To use this software for the above reasons, you will need to gain access to the Google Drive API and generate a Credential
using the following steps from the PyDrive documentation:
Drive API requires OAuth2.0 for authentication. PyDrive makes your life much easier by handling complex authentication steps for you.
Go to APIs Console and make your own project.
Search for ‘Google Drive API’, select the entry, and click ‘Enable’.
Select ‘Credentials’ from the left menu, click ‘Create Credentials’, select ‘OAuth client ID’.
Now, the product name and consent screen need to be set -> click ‘Configure consent screen’ and follow the instructions. Once finished:
Select ‘Application type’ to be Web application.
Enter an appropriate name.
Input http://localhost:8080 for ‘Authorized JavaScript origins’.
Input http://localhost:8080/ for ‘Authorized redirect URIs’.
Click ‘Save’.
Click ‘Download JSON’ on the right side of Client ID to download client_secret_<really long ID>.json.
The downloaded file has all authentication information of your application. Rename the file to “client_secrets.json” and place it in your working directory.
Source: https://pythonhosted.org/PyDrive/
"""
__author__ = "Aaron Mauro"
__role__ = "researcher"
__institution__ = "Brock University"
__email__ = "amauro@brocku.ca"
__status__ = "prototype/experiment"
__version__ = "0.1"
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
import datetime
import time
message_for_google = "don't be evil! " * 1000000 # power levels to a million!
# Results in a 14 MB file, from just 15 characters
number_of_files = 1 # increase number of files to add to Google Drive
# Guide: 15 GB = 15360 MB / 14MB = ~1097 files
gauth = GoogleAuth()
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)
def main(message):
# list files and deletes your Google Drive
file_list = drive.ListFile({'q': "'root' in parents and trashed=true"}).GetList()
print(f"Deleting {len(file_list)} files in your Google Drive.")
for i in range(10,0,-1):
print(f"Cancel this process in {i} seconds, press Ctrl. + c")
time.sleep(1)
print("Here we go!")
for file in file_list:
print(f"Deleting --> title: {file['title']}, id: {file['id']}")
#file.Delete() # Uncomment to permanently delete all Google Drive files
print()
print("Generating message...")
# Stuff your Google Drive with a fairwell message
for num_file in range(number_of_files):
title = message.split()[0]+str(num_file)
file_stuff = drive.CreateFile({'title': f'{title}.txt'})
file_stuff.SetContentString(message)
file_stuff.Upload()
if __name__ == "__main__":
try:
start = datetime.datetime.now()
main(message_for_google)
finish = datetime.datetime.now()
print(f"Runtime: {finish - start}")
print("Done.")
except len(message_for_google) == 0:
print("Please include a message...")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment