From e76ab4c74b7f3cdb2a8b32f29779da634c9adf9b Mon Sep 17 00:00:00 2001 From: Dan Dembinski Date: Fri, 6 Mar 2020 13:54:51 -0500 Subject: [PATCH] Started setting this up as an API --- main.py | 54 ++++++++++++++++++++++++++++++++++++++++-------- requirements.txt | 7 +++++++ 2 files changed, 52 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index 0d84950..bda4c37 100644 --- a/main.py +++ b/main.py @@ -1,25 +1,61 @@ import database as db import Feed -import time +from flask import request, url_for +from flask_api import FlaskAPI, status, exceptions -userID = None +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() - print(result[0]) - return result[0] -userID = login() +@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 + +if __name__ == "__main__": + app.run(debug=True) -while True: - Feed.updateFeeds(userID) - time.sleep(3600) diff --git a/requirements.txt b/requirements.txt index 2139b25..4177e4e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,12 @@ +Click==7.0 feedparser==5.2.1 +Flask==1.1.1 +Flask-API==2.0 +itsdangerous==1.1.0 +Jinja2==2.11.1 lxml==4.5.0 +MarkupSafe==1.1.1 opml==0.5 PyMySQL==0.9.3 SQLAlchemy==1.3.13 +Werkzeug==1.0.0