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)
|
podcastID = db.Column(db.Integer)
|
||||||
userID = db.Column(db.Integer)
|
userID = db.Column(db.Integer)
|
||||||
link = db.Column(db.Text)
|
link = db.Column(db.Text)
|
||||||
started = db.Column(db.Boolean)
|
started = db.Column(db.Boolean, default=0)
|
||||||
position = db.Column(db.Text)
|
position = db.Column(db.Text, default=0)
|
||||||
|
|
||||||
|
|
||||||
class podcasts(db.Model):
|
class podcasts(db.Model):
|
||||||
@@ -43,48 +43,41 @@ def login():
|
|||||||
password = 'password'
|
password = 'password'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
user = Users.query.filter_by(username=username).first()
|
user = users.query.filter_by(username=username).first()
|
||||||
except:
|
except:
|
||||||
jsonify({'message': 'Login Failed'})
|
jsonify({'message': 'Login Failed'})
|
||||||
return jsonify(userid=user.userID)
|
return jsonify(userid=user.userID)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/updateFeeds/<int:userID>/', methods={'GET'})
|
@app.route('/updateFeeds/<int:userID>/', methods={'POST'})
|
||||||
def updateFeeds(userID):
|
def updateFeeds(userID):
|
||||||
showCheck = []
|
showCheck = []
|
||||||
updatedShows = []
|
updatedShows = []
|
||||||
|
|
||||||
|
|
||||||
# grabs podcast urls from logged in user
|
# grabs podcast urls from logged in user
|
||||||
query = db.sql.text("""select URL, podcastID, title from Podcasts where userID = %i""" % userID)
|
pc = podcasts.query.filter_by(userID=userID).all()
|
||||||
shows = db.con.execute(query).fetchall()
|
|
||||||
|
|
||||||
# loops through the returned urls and parses each rss feed
|
# loops through the returned urls and parses each rss feed
|
||||||
y = 0
|
for show in pc:
|
||||||
for x in shows:
|
parsed = fp.parse(show.URL)
|
||||||
# Here we're grabbing all the show urls for each podcast and moving them into a separate array.
|
query = shows.query.filter_by(podcastID=show.podcastID).all()
|
||||||
query = db.sql.text("""select link from Shows where userID = %i and podcastID = %i""" % (userID, shows[y][1]))
|
for x in query:
|
||||||
showGrab = db.con.execute(query).fetchall()
|
showCheck.append(x.link)
|
||||||
z = 0
|
|
||||||
for each in showGrab:
|
|
||||||
showCheck.append(showGrab[z][0])
|
|
||||||
z = z + 1
|
|
||||||
|
|
||||||
parsed = fp.parse(shows[y][0])
|
|
||||||
count = 0
|
count = 0
|
||||||
for items in parsed['entries']:
|
for items in parsed['entries']:
|
||||||
url = parsed.entries[count].enclosures[0].get('href')
|
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
|
# 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:
|
if url not in showCheck:
|
||||||
query = db.sql.text("""insert into Shows (podcastID, userID, link) values (%i, %i, \"%s\")""" % (
|
query = shows(podcastID=show.podcastID, userID=userID, link=url)
|
||||||
shows[y][1], userID, url))
|
db.session.add(query)
|
||||||
db.con.execute(query)
|
db.session.commit()
|
||||||
updatedShows.append(shows[y][2])
|
updatedShows.append(show.title)
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
count = count + 1
|
count = count + 1
|
||||||
y = y + 1
|
# Clear out the array for the next podcast
|
||||||
showCheck = [] # Clear out the array for the next podcast
|
showCheck = []
|
||||||
return jsonify(updatedShows)
|
return jsonify(updatedShows)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user