aboutsummaryrefslogtreecommitdiffstats
path: root/seer.py
diff options
context:
space:
mode:
Diffstat (limited to 'seer.py')
-rwxr-xr-xseer.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/seer.py b/seer.py
index 9aa23fe..9219495 100755
--- a/seer.py
+++ b/seer.py
@@ -14,8 +14,10 @@ from tfann import tfann_type_1
from cnn import cnn_type_1
import httplib2
from googleapiclient.discovery import build
+from googleapiclient.http import MediaIoBaseDownload
import googleapiclient.http
import oauth2client.client
+import io
def SigHandler_SIGINT(signum, frame):
print()
@@ -25,6 +27,7 @@ class Argparser(object):
def __init__(self):
parser = argparse.ArgumentParser()
parser.add_argument("--which", type=str, help="which one to run")
+ parser.add_argument("--download", type=str, help="file name to download")
parser.add_argument("--what", type=str, help="train or predict")
parser.add_argument("--pysrcupdate", type=str, nargs="+", help="name of source files to update on the drive")
parser.add_argument("--gpu", action="store_true", help="use gpu. if false will use cpu", default=False)
@@ -68,6 +71,43 @@ def g_drive_up(file_path, file_name, file_type, to_folder):
print(new_file.get("id"))
#pprint.pprint(new_file)
+def g_drive_down(folder_name, file_name):
+ OAUTH2_SCOPE = "https://www.googleapis.com/auth/drive"
+ CLIENT_SECRETS = "./secret.json"
+ flow = oauth2client.client.flow_from_clientsecrets(CLIENT_SECRETS, OAUTH2_SCOPE)
+ flow.redirect_uri = oauth2client.client.OOB_CALLBACK_URN
+ authorize_url = flow.step1_get_authorize_url()
+ print('Go to the following link in your browser: ' + authorize_url)
+ code = input('Enter verification code: ').strip()
+ credentials = flow.step2_exchange(code)
+ http = httplib2.Http()
+ credentials.authorize(http)
+ drive_service = build('drive', 'v3', http=http)
+
+ #get folder id
+ parent_dir = drive_service.files().list(q="mimeType='application/vnd.google-apps.folder' and name='"+folder_name+"'", fields="files(id, name)", spaces="drive").execute()
+ folder_id = str()
+ for file in parent_dir.get("files", []):
+ print(file.get("name") + "---" + file.get("id"))
+ folder_id = file.get("id")
+
+ #get file id
+ download_to_be = drive_service.files().list(q="name='"+file_name+"' and '"+folder_id+"' in parents", fields="files(id, name)", spaces="drive").execute()
+ file_id = str()
+ for file in download_to_be.get("files", []):
+ print(file.get("name") + "---" + file.get("id"))
+ file_id = file.get("id")
+
+ request = drive_service.files().get_media(fileId=file_id)
+ #fh = io.BytesIO()
+ fh = io.FileIO(file_name, "w")
+ downloader = MediaIoBaseDownload(fh, request)
+ done = False
+ while done is False:
+ status, done = downloader.next_chunk()
+ print("Download %d%%." % int(status.progress() * 100))
+ #print(downloader)
+
def launch_ais(which):
if which == "marionette": marrionette_type_1()
elif which == "lstm_type_1": lstm_type_1("ethereum", "ether")
@@ -84,6 +124,8 @@ def premain(argparser):
if argparser.args.pysrcupdate:
for src in argparser.args.pysrcupdate:
g_drive_up(src, get_name_from_path(src), "text/python", "colab")
+ if argparser.args.download:
+ g_drive_down("colab", "main.py")
launch_ais(argparser.args.which)
def main():