Ejemplo n.º 1
0
def get_speech_service():
    credentials = GoogleCredentials.get_application_default().create_scoped(
        ['https://www.googleapis.com/auth/cloud-platform'])
    http = httplib2.Http()
    credentials.authorize(http)

    return discovery.build(
        'speech', 'v1beta1', http=http, discoveryServiceUrl=DISCOVERY_URL)
Ejemplo n.º 2
0
def get_speech_service():
    credentials = GoogleCredentials.get_application_default().create_scoped(
        ['https://www.googleapis.com/auth/cloud-platform'])
    http = httplib2.Http()
    credentials.authorize(http)

    return discovery.build('speech',
                           'v1beta1',
                           http=http,
                           discoveryServiceUrl=DISCOVERY_URL)
def copy_to_drive(resized_img_path, resized_image):
    credentials = get_credentials()
    http = credentials.authorize(httplib2.Http())
    drive_service = discovery.build('drive', 'v3', http=http)

    folder_id = 'id_of_google_drive_folder' # Enter id of drive folder
    file_metadata = {
      'name' : resized_image,
      'parents': [ folder_id ]
    }
    media = MediaFileUpload(resized_img_path,
                            mimetype='image/jpeg',
                            resumable=True)
    file = drive_service.files().create(body=file_metadata,
                                        media_body=media,
                                        fields='id').execute()
    print(f'File ID: {file.get('id')}')
Ejemplo n.º 4
0
def redirect_page():
    global user_logged_in

    if not user_logged_in:
       bottle.redirect("/")

    code = request.query.get('code', '')
    CLIENT_ID = "568897491390-rbnckuesgmpra3qggo4h4hu9j3qs7m08.apps.googleusercontent.com"
    CLIENT_SECRET = "nRbISCqK45lvYRXzA8l7XpM-"
    SCOPE = 'https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/userinfo.email'

    flow = OAuth2WebServerFlow(client_id=CLIENT_ID, client_secret=CLIENT_SECRET, scope=SCOPE, redirect_uri="/redirect")
    credentials = flow.step2_exchange(code)
    token = credentials.id_token['sub']

    response.set_cookie("token", str(token)) #store token

    http = httplib2.Http()
    http = credentials.authorize(http)
    
    # Get user email
    users_service = build('oauth2', 'v2', http=http)
    user_document = users_service.userinfo().get().execute()
    user_email = user_document['email']

    response.set_cookie("email", str(user_email)) #store user's email

    output = '''
<html>
<head>
	<style>	
	body {
		background-image: linear-gradient(to top, #f4fdff, white);
		background-repeat: no-repeat;
		height: 100%;
		overflow: hidden;
		}
	
	.main {
		position: absolute;
		top: 45%;
		left: 50%;
		transform: translate(-50%, -50%);
		text-align: center;
		}
	.search-box {
		height: 30px;
		border-radius: 40px;
		padding: 10px;
		border-style: solid;
		border-color: #72e7ff;
		background: white;
		transition: 0.4s;
		box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
		}
				
	.search-box:hover, .search-box:focus-within {
		height: 40px;
		background: #72e7ff;
		box-shadow: none;
		}
	
	.search-txt {
		border: none;
		background: none;
		outline: none;
		float: center;
		text-align: center;
		padding: 0;
		color: #036c82;
		font-size: 20px;
		line-height: 40px;
		width: 800px;
		}
			
	#submit {
		border: none;
		background: white;
		transition: 0.4s;
		border-radius: 40px;
		width: 200px;
		line-height: 30px;
		box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 3px 10px 0 rgba(0, 0, 0, 0.19);
		font-size: 16px;
		}
		
	#submit:hover {
		background: #72e7ff;
		border-color: #72e7ff;
		border-style: solid;
		border-width: 5px;
		box-shadow: none;
		}
	
	.nav {
		background: #72e7ff;
		width: 100%;
		height: 8%;
		padding: 0;
		box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.2), 0 2px 5px 0 rgba(0, 0, 0, 0.19);
		padding-top: 0.5%;
		padding-right: 5%;
		}
		
	#login {
		border: none;
		background: white;
		transition: 0.4s;
		border-radius: 40px;
		height: 50px;
		width: 150px;
		line-height: 30px;
		font-size: 16px;
		float: right;
		margin-top: 0.5%;
		}
		
	#login:hover {
		border-color: white;
		border-style: solid;
		border-width: 3px;
		background: #72e7ff;
		color: white;
		font-weight: bold;
		box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.2), 0 2px 5px 0 rgba(0, 0, 0, 0.19);
		}
		
	#toptext {
		float: left;
		font-family: sans-serif;
		padding-left: 1%;
		color: #036c82;
		font-style: italic;
		}
		
	#title {
		color: #036c82;
		font-family: sans-serif;
		font-size: 48px;
		}

	#help {
		background: white;
		transition: 0.4s;
		border-radius: 40px;
		width: 50px;
		line-height: 30px;
		box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 3px 10px 0 rgba(0, 0, 0, 0.19);
		font-size: 16px;
		border: none;
	}
	
	#help:hover {
		background: #72e7ff;
		box-shadow: none;
		}
	
	#help:hover ~ #tips{
		visibility: visible;
		}
		
	#tips {
		visibility: hidden;
		transition: 0.2s;
		text-align: center;
		color: #036c82;
		font-family: sans-serif;
		border-color: #72e7ff;
		border-style: solid;
		border-width: 3px;
		background-color: white;
		box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
		padding-left: 3%;
		padding-right: 3%;
		}
		
	h3 {
		font-size: 24px;
		}
		
	p {
		font-size: 20px;
		}
	
    </style>
</head>
<body>
	<section id="hero">
	<div class="nav">'''
    output += '''<h2 id="toptext">Welcome, ''' + user_email + '''.</h2>'''
    output += '''
<a href="/logout"><button id="login" type="button" class="btn">Log Out</button></a>
	</div>
	<div class="main">
		<form id="form" method="post">
			<h1 id="title">Search the web:</h1>
			<div class="search-box">
				<input name="keywords" id="keywords" type="text" placeholder="Enter your phrase..." class="search-txt"/>
			</div>
			<br><br><input name="search" id="submit" type="submit" value="Search" class="btn"></input>
			<button id="help" type="button" class="btn">?</button><br><br>
			<div id="tips">
				<h3>Search tips:</h3>
				<p>To perform mathematical calculations, type "Calculate:" followed by the expression you want to calculate."</p>
				<p>To get the definition of a word, type "Define:" followed by the word you want to know.</p>
			</div>
		</form>
	</div>
    </section>
<body>
</html>
'''
    return output
try:
    import argparse
    flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
except ImportError:
    flags = None

##sending params to get credentials
SCOPES = 'https://www.googleapis.com/auth/drive'
CLIENT_SECRET_FILE = 'client_secret.json'
APPLICATION_NAME = 'MARS PHOTO UPLOADER'
creds_obj = credentials.credentials(SCOPES, CLIENT_SECRET_FILE,
                                    APPLICATION_NAME)
credentials = creds_obj.get_credentials()

##creating link
http = credentials.authorize(httplib2.Http())
drive_service = build('drive', 'v3', http)


##upload files to mars_photos folder
def upload(filename, filepath, mimetype):
    folder_id = '1Ew6RTaoTrlJNfurpjQfHWaI6x9etGwH2'
    file_metadata = {'name': filename, 'parents': [folder_id]}
    media = MediaFileUpload(filepath, mimetype=mimetype, resumable=True)
    file = drive_service.files().create(body=file_metadata,
                                        media_body=media,
                                        fields='id').execute()
    print('File ID: %s' % file.get('id'))


#photos