Hoy empezamos la segunda tarea programada del semestre. Al principio pensamos que iba a ser muy difícil por el hecho de que tenemos que vincular nuestro programa de python con dropbox, pero no dimos cuenta que al parecer es más sencillo de lo esperado. Encontramos el siguiente código que nos puede ayudar mucho:
import dropbox
#from Dropbox import client
# Get your app key and secret from the Dropbox developer website
app_key = 'xxxxxxxxxxxxxx'
app_secret = 'xxxxxxxxxxx'
flow = dropbox.client.DropboxOAuth2FlowNoRedirect(app_key, app_secret)
# Have the user sign in and authorize this token
authorize_url = flow.start()
print '1. Go to: ' + authorize_url
print '2. Click "Allow" (you might have to log in first)'
print '3. Copy the authorization code.'
code = raw_input("Enter the authorization code here: ").strip()
# This will fail if the user enters an invalid authorization code
access_token, user_id = flow.finish(code)
client = dropbox.client.DropboxClient(access_token)
print 'linked account: ', client.account_info()
f = open('working-draft.txt', 'rb')
response = client.put_file('/magnum-opus.txt', f)
print 'uploaded: ', response
folder_metadata = client.metadata('/')
print 'metadata: ', folder_metadata
f, metadata = client.get_file_and_metadata('/magnum-opus.txt')
out = open('magnum-opus.txt', 'wb')
out.write(f.read())
out.close()
print metadata
Las llaves públicas y privadas se consiguen creando una aplicación en dropbox (que es muy sencillo), sin embargo tenemos que instalar los módulos que necesitamos para la librería dropbox con el powerShell.
No hay comentarios:
Publicar un comentario