from flask import Flask, render_template, request, jsonify
import os
import shutil
import requests

app = Flask(__name__)
app.config.from_object('config.Debug')

@app.route('/upload', methods=['GET', 'POST'])
def upload():

    if request.method == 'GET':

        return render_template('upload.html')

    elif request.method == 'POST':

        file = request.files['file']

        if file:

            filename = os.urandom(30).encode('hex') + '.' + file.filename.split('.')[-1]

            while os.path.isfile(os.path.join(app.config['TEMP_DIR'], filename)):

                filename = os.urandom(30).encode('hex')

            file.save(os.path.join(app.config['TEMP_DIR'], filename))

            return jsonify(filename=filename)

@app.route('/confirm/<filename>/<id>', methods=['POST'])
def confirm(filename, id):

    r = requests.get('https://www.googleapis.com/books/v1/volumes/s1gVAAAAYAAJ').json()

    print r['id']

    if os.path.isfile(os.path.join(app.config['TEMP_DIR'], filename)):

        shutil.move(os.path.join(app.config['TEMP_DIR'], filename), os.path.join(app.config['LIB_DIR'], r['id']+'.'+filename.split('.')[-1]))

    return ''

if __name__ == "__main__":

	  app.run()

from flask import Flask, render_template, request, jsonify
import os
import shutil

app = Flask(__name__)
app.config.from_object('config.Debug')

@app.route('/upload', methods=['GET', 'POST'])
def upload():

    if request.method == 'GET':

        return render_template('upload.html')

    elif request.method == 'POST':

        file = request.files['file']

        if file:

            filename = os.urandom(30).encode('hex') + '.' + file.filename.split('.')[-1]

            while os.path.isfile(os.path.join(app.config['TEMP_DIR'], filename)):

                filename = os.urandom(30).encode('hex')

            file.save(os.path.join(app.config['TEMP_DIR'], filename))

            return jsonify(filename=filename)

@app.route('/confirm/<filename>/<id>', methods=['POST'])
def confirm(filename, id):

    if os.path.isfile(os.path.join(app.config['TEMP_DIR'], filename)):

        shutil.move(os.path.join(app.config['TEMP_DIR'], filename), os.path.join(app.config['LIB_DIR'], filename))

    return ''

if __name__ == "__main__":

	  app.run()

--- 
+++ 
@@ -1,6 +1,7 @@
 from flask import Flask, render_template, request, jsonify
 import os
 import shutil
+import requests
 
 app = Flask(__name__)
 app.config.from_object('config.Debug')
@@ -31,9 +32,13 @@
 @app.route('/confirm/<filename>/<id>', methods=['POST'])
 def confirm(filename, id):
 
+    r = requests.get('https://www.googleapis.com/books/v1/volumes/s1gVAAAAYAAJ').json()
+
+    print r['id']
+
     if os.path.isfile(os.path.join(app.config['TEMP_DIR'], filename)):
 
-        shutil.move(os.path.join(app.config['TEMP_DIR'], filename), os.path.join(app.config['LIB_DIR'], filename))
+        shutil.move(os.path.join(app.config['TEMP_DIR'], filename), os.path.join(app.config['LIB_DIR'], r['id']+'.'+filename.split('.')[-1]))
 
     return ''
 
Save confirmed files with Google Books ID
