import database as db import Feed from flask import request, url_for from flask_api import FlaskAPI, status, exceptions app = FlaskAPI(__name__) @app.route('/') def index(): return { 'stuff' } @app.route('/login') def login(): username = 'Dan' password = 'password' query = db.sql.text(""" select userID from Users where username = \'%s\'""" % username) result = db.con.execute(query).fetchone() return result[0] @app.route('/updateFeeds//') def updateFeeds(userID): showCheck = [] # grabs podcast urls from logged in user query = db.sql.text("""select URL, podcastID, title from Podcasts where userID = %i""" % userID) shows = db.con.execute(query).fetchall() # loops through the returned urls and parses each rss feed y = 0 for x in shows: # Here we're grabbing all the show urls for each podcast and moving them into a separate array. query = db.sql.text("""select link from Shows where userID = %i and podcastID = %i""" % (userID, shows[y][1])) showGrab = db.con.execute(query).fetchall() z = 0 for each in showGrab: showCheck.append(showGrab[z][0]) z = z + 1 parsed = fp.parse(shows[y][0]) count = 0 for items in parsed['entries']: url = parsed.entries[count].enclosures[0].get('href') # after parsing out the show URL we check if it already exists by comparing it against the showCheck array containing all show URLs if url not in showCheck: query = db.sql.text("""insert into Shows (podcastID, userID, link) values (%i, %i, \"%s\")""" % ( shows[y][1], userID, url)) db.con.execute(query) print("%s has a new show" % shows[y][2]) else: continue count = count + 1 y = y + 1 showCheck = [] # Clear out the array for the next podcast