Save json every X time in mongodb python flask

1

The problem I think occurs when you try to do db = mongo.bd.openweathermap, what appears to me by console

No handlers could be found for logger "apscheduler.executors.default"

from flask import Flask, render_template, request, jsonify, redirect, url_for
from flask_pymongo import PyMongo
import requests
from pprint import pprint
import json
from flask_apscheduler import APScheduler


class Config(object):
    JOBS = [
        {
            'id': 'llamadaTiempo',
            'func': '__main__:llamadaOpenweathermap',
            'trigger': 'interval',
            'seconds': 5
        }

    ]

def llamadaOpenweathermap():
    resp_openweathermap = requests.get('http://api.openweathermap.org/data/2.5/forecast?id=6358500&lang=es&units=metric&appid=61fc69899d1418f150674aaacbdbae40')
    db = mongo.db.openweathermap
    db.insert(resp_openweathermap.json())

app = Flask(__name__)

app.config.from_object(Config())

scheduler = APScheduler()
scheduler.api_enabled = True
scheduler.init_app(app)

scheduler.start()

#Conexion BD 
app.config['MONGO_DBNAME'] = 'bdPrueba'
app.config['MONGO_URI'] = 'mongodb://localhost:27017/bdPrueba'
mongo = PyMongo(app)


@app.route('/')
def index():
    return render_template('index.html')


if __name__ == '__main__':
    app.run()
    
asked by Jose Antonio 05.04.2017 в 16:03
source

0 answers