#!/usr/bin/env python import os, random, sys, web from dropbox import client, session """ GLOBAL VARIABLES """ APP_KEY = '' APP_SECRET = '' ACCESS_TYPE = 'dropbox' URLURL = '' """ SESSION CLASS """ class StoreSess(session.DropboxSession): TOKEN_FILE = "token.txt" def load_creds(self): try: fh = open(self.TOKEN_FILE) stored_creds = fh.read() fh.close() self.set_token(*stored_creds.split("|")) except IOError: pass def save_creds(self, token): fh = open(self.TOKEN_FILE, "w") fh.write("|".join([token.key, token.secret])) fh.close() def link(self): request_token = self.obtain_request_token() url = self.build_authorize_url(request_token) print "Go to:", url print "Please authorize in the browser. After you're done, press enter." raw_input() self.obtain_access_token(request_token) self.save_creds(self.token) """ URLS """ urls = ( '/', 'Index', '/quit', 'Quit', ) """ HANDLER CLASSES """ class Index: def GET(self): dbsess = StoreSess(APP_KEY, APP_SECRET, ACCESS_TYPE) dbsess.load_creds() dbclient = client.DropboxClient(dbsess) resp = dbclient.metadata("Public/parity/sm") dir = [] if 'contents' in resp: for f in resp['contents']: name = os.path.basename(f['path']) dir.append(name) return self.html(random.choice(dir)) def html(self, image): if len(image) == 0: return "No image" html = """