Started setting this up as an API

This commit is contained in:
Dan Dembinski
2020-03-06 13:54:51 -05:00
parent 4c7fdaf66a
commit e76ab4c74b
2 changed files with 52 additions and 9 deletions

54
main.py
View File

@@ -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/<string:userID>/')
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)