Signed-off-by: Jeroen Oudshoorn <oudshoorn.jeroen@gmail.com>
This commit is contained in:
Jeroen Oudshoorn
2023-10-14 07:43:34 +02:00
parent b98c1e10e3
commit eab3f1c222

View File

@ -7,7 +7,6 @@ import pwnagotchi
import pydrive2 import pydrive2
from pydrive2.auth import GoogleAuth from pydrive2.auth import GoogleAuth
from pydrive2.drive import GoogleDrive from pydrive2.drive import GoogleDrive
from pwnagotchi.google import cmd as google_cmd
class GdriveSync(plugins.Plugin): class GdriveSync(plugins.Plugin):
@ -46,8 +45,14 @@ class GdriveSync(plugins.Plugin):
try: try:
gauth = GoogleAuth(settings_file="/root/settings.yaml") gauth = GoogleAuth(settings_file="/root/settings.yaml")
gauth.LoadCredentialsFile("/root/credentials.json") gauth.LoadCredentialsFile("/root/credentials.json")
gauth.Authorize() if gauth.credentials is None:
# Authenticate if they're not there
gauth.LocalWebserverAuth()
elif gauth.access_token_expired:
# Refresh them if expired
gauth.Refresh()
gauth.SaveCredentialsFile("/root/credentials.json") gauth.SaveCredentialsFile("/root/credentials.json")
gauth.Authorize()
# Create GoogleDrive instance # Create GoogleDrive instance
self.drive = GoogleDrive(gauth) self.drive = GoogleDrive(gauth)
@ -109,7 +114,7 @@ class GdriveSync(plugins.Plugin):
for file in file_list: for file in file_list:
if file['title'] == folder_name: if file['title'] == folder_name:
return file['id'] return file['id']
return None return None
def on_unload(self, ui): def on_unload(self, ui):
logging.info("[gdrivesync] unloaded") logging.info("[gdrivesync] unloaded")