Started setting this up as an API
This commit is contained in:
54
main.py
54
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/<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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user