Reworked addFeed method and have that working correctly now. Started adding updateStatus method.
This commit is contained in:
48
main.py
48
main.py
@@ -1,6 +1,8 @@
|
||||
import feedparser as fp
|
||||
from flask import Flask, jsonify
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from urllib.parse import unquote_plus
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||
@@ -72,51 +74,49 @@ def updateFeeds(userID):
|
||||
query = shows(podcastID=show.podcastID, userID=userID, link=url)
|
||||
db.session.add(query)
|
||||
db.session.commit()
|
||||
updatedShows.append(show.title)
|
||||
new_show = {}
|
||||
new_show['title'] = show.title
|
||||
updatedShows.append(new_show)
|
||||
else:
|
||||
continue
|
||||
count = count + 1
|
||||
# Clear out the array for the next podcast
|
||||
showCheck = []
|
||||
return jsonify(updatedShows)
|
||||
return jsonify(newShows=updatedShows)
|
||||
|
||||
|
||||
|
||||
# @app.route('/addFeed/<int:userID>/<string:newURL>', methods=['PUT'])
|
||||
@app.route('/addFeed/<int:userID>/', methods=['PUT'])
|
||||
@app.route('/addFeed/<int:userID>/<path:newURL>', methods=['PUT'])
|
||||
def addFeed(userID,newURL):
|
||||
|
||||
count = 0
|
||||
|
||||
parsed = fp.parse(newURL)
|
||||
|
||||
title = parsed.feed.title
|
||||
artwork = parsed.feed.image
|
||||
title = str(parsed.feed.title)
|
||||
artwork = str(parsed.feed.image)
|
||||
|
||||
# checks to see if the podcast URL already exists for logged in user and skips it if it has already been imported.
|
||||
query = db.sql.text("""select URL from Podcasts where URL = \"%s\" and userID = %i""" % (newURL, userID))
|
||||
exists = db.con.execute(query).fetchone()
|
||||
# if the show doesn't already exist for the logged in user it gets added
|
||||
if exists is None or exists[0] != newURL:
|
||||
query = db.sql.text("""insert into Podcasts (userID, title, URL, artworkURL) values(%i, \"%s\", \"%s\", \"%s\") """ % (userID, title, newURL, artwork))
|
||||
db.con.execute(query)
|
||||
print("%s added" % title)
|
||||
if not podcasts.query.filter_by(URL=newURL, userID=userID).first():
|
||||
query = podcasts(userID=userID, title=title, URL=newURL, artworkURL=artwork)
|
||||
db.session.add(query)
|
||||
db.session.commit()
|
||||
# Once the podcast is added we grab the podcastID so we can import the shows
|
||||
query = db.sql.text("""select podcastID from Podcasts where userID = %i and URL = \"%s\"""" % (userID, newURL))
|
||||
result = db.con.execute(query).fetchone()
|
||||
podcastID = result[0]
|
||||
|
||||
result = podcasts.query.filter_by(URL=newURL, userID=userID).first()
|
||||
# Import the new shows. No need to check if the show URLS already exist since it's new
|
||||
for items in parsed['entries']:
|
||||
itemURL = parsed.entries[count].enclosures[0].get('href')
|
||||
query = db.sql.text("""insert into Shows (podcastID, userID, link) values (%i, %i, \"%s\")""" % (podcastID, userID, itemURL))
|
||||
db.con.execute(query)
|
||||
query = shows(podcastID=result.podcastID, userID=userID, link=itemURL)
|
||||
db.session.add(query)
|
||||
count = count + 1
|
||||
return ("%s added" % title)
|
||||
db.session.commit()
|
||||
return jsonify(message='Podcast added')
|
||||
else:
|
||||
return ("%s already exists" % title)
|
||||
return jsonify(message='Podcast already exists')
|
||||
|
||||
@app.route('/listShows/<int:userID>/', methods=['GET'])
|
||||
def listShows(userID):
|
||||
@app.route('/listPodcasts/<int:userID>/', methods=['GET'])
|
||||
def listPodcasts(userID):
|
||||
output = []
|
||||
y = 0
|
||||
# grabs podcast urls from logged in user
|
||||
@@ -143,7 +143,9 @@ def register(username, password, name, email):
|
||||
# if the username doesn't already exist it will be added
|
||||
else:
|
||||
return jsonify(message='Username already exists')
|
||||
|
||||
@app.route('/updateStatus/<int:userID>/<int:podcastID>/<int:status>')
|
||||
def updateStatus(userID, podcastID, status):
|
||||
return ''
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host='0.0.0.0', debug=True)
|
||||
Reference in New Issue
Block a user