Skip to content

Instantly share code, notes, and snippets.

@Jul10l1r4
Last active January 2, 2019 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jul10l1r4/2dbdf1d7ff70a96fb823f61aa3034592 to your computer and use it in GitHub Desktop.
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.
#!/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:senha@route.com/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