Home > Blockchain >  Why is my Second function not working in python
Why is my Second function not working in python

Time:06-07

I have created two functions get_feeds_ui() and get_feeds_ol() to try and get the data from the rss feeds URLS. The first function is returning data but the second function is not. Anyone know what is missing or what I need to do? I am new with python.

from flask import Flask ,jsonify
from flask_cors import CORS, cross_origin
app = Flask(__name__)
CORS(app, resources={r"/api/*":{"origins":"*"}})
app.config['CORS HEADERS'] = 'Content-Type' 
URLS =['https://status.ui.com/history.rss',
'http://status.us.onelogin.com/pages/538511e2ce5cb97537000144/rss']


@app.route("/feed", methods=['POST','GET'])
@cross_origin()

def get_feeds_ui():
    feed = feedparser.parse(URLS[0])
    first_article = feed['entries'][0]
    
    return jsonify(title=first_article.title,
         link=first_article.link, 
         updated=first_article.updated)

def get_feeds_ol():
    feed = feedparser.parse(URLS[1])  
    first_article = feed['entries'][0]

    return jsonify(title=first_article.title,
    link=first_article.link,
    updated=first_article.updated)
  
if __name__ == '__main__':
    app.run(debug=True)

CodePudding user response:

You didn't specify the URL on your 2nd function. You need to specify URLs on every function you are using as api.

@app.route("/feed_ol", methods=['POST','GET'])
def get_feeds_ol():
    feed = feedparser.parse(URLS[1])  
    first_article = feed['entries'][0]

    return jsonify(title=first_article.title,
    link=first_article.link,
    updated=first_article.updated)
  • Related