Last active
January 2, 2019 15:41
-
-
Save Jul10l1r4/2dbdf1d7ff70a96fb823f61aa3034592 to your computer and use it in GitHub Desktop.
Esse exemplo é uma mini API em flask que faz requisição ao banco nos EUA e entrega o blob de três imagens em base64.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# -*- Coding: utf-8 -*- | |
from multiprocessing.dummy import Pool as ThreadPool | |
from flask import Flask, jsonify | |
from pymongo import MongoClient | |
import os | |
app = Flask(__name__) | |
# Conectio my | |
client = MongoClient('mongodb://example:[email protected]/images',45704) | |
db = client.images | |
# API work | |
@app.route('/') | |
def main (): | |
# Defining threads, 2 registers | |
pool = ThreadPool(2) | |
# Selecting colletion | |
collection = db['blobs'] | |
#cursor = collection.find({}) | |
def make(x): | |
# The values get information by type | |
return 'Fuckindata {"buf":"'+str(collection.find_one({"type":x})["data"])+'"}' | |
# Make a loop in cursor, in collection | |
blob = pool.map(make,['a','b','c']) | |
pool.close() | |
pool.join() | |
return jsonify(blob) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment