Updated feedUpdate method
This commit is contained in:
39
main.py
39
main.py
@@ -22,8 +22,8 @@ class shows(db.Model):
|
||||
podcastID = db.Column(db.Integer)
|
||||
userID = db.Column(db.Integer)
|
||||
link = db.Column(db.Text)
|
||||
started = db.Column(db.Boolean)
|
||||
position = db.Column(db.Text)
|
||||
started = db.Column(db.Boolean, default=0)
|
||||
position = db.Column(db.Text, default=0)
|
||||
|
||||
|
||||
class podcasts(db.Model):
|
||||
@@ -43,48 +43,41 @@ def login():
|
||||
password = 'password'
|
||||
|
||||
try:
|
||||
user = Users.query.filter_by(username=username).first()
|
||||
user = users.query.filter_by(username=username).first()
|
||||
except:
|
||||
jsonify({'message': 'Login Failed'})
|
||||
return jsonify(userid=user.userID)
|
||||
|
||||
|
||||
@app.route('/updateFeeds/<int:userID>/', methods={'GET'})
|
||||
@app.route('/updateFeeds/<int:userID>/', methods={'POST'})
|
||||
def updateFeeds(userID):
|
||||
showCheck = []
|
||||
updatedShows = []
|
||||
|
||||
|
||||
# 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()
|
||||
pc = podcasts.query.filter_by(userID=userID).all()
|
||||
|
||||
# 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])
|
||||
for show in pc:
|
||||
parsed = fp.parse(show.URL)
|
||||
query = shows.query.filter_by(podcastID=show.podcastID).all()
|
||||
for x in query:
|
||||
showCheck.append(x.link)
|
||||
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)
|
||||
updatedShows.append(shows[y][2])
|
||||
query = shows(podcastID=show.podcastID, userID=userID, link=url)
|
||||
db.session.add(query)
|
||||
db.session.commit()
|
||||
updatedShows.append(show.title)
|
||||
else:
|
||||
continue
|
||||
count = count + 1
|
||||
y = y + 1
|
||||
showCheck = [] # Clear out the array for the next podcast
|
||||
# Clear out the array for the next podcast
|
||||
showCheck = []
|
||||
return jsonify(updatedShows)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user