Removed unneeded files for API version. Cleaned up main.py. Removed unnecessary packages from requirements.txt.
This commit is contained in:
117
Feed.py
117
Feed.py
@@ -1,117 +0,0 @@
|
||||
import opml
|
||||
import feedparser as fp
|
||||
import database as db
|
||||
|
||||
|
||||
def feedImport (userID):
|
||||
outline = opml.parse("podcast_republic_podcasts.opml")
|
||||
#get the number of shows from the OPML file
|
||||
x = len(outline)
|
||||
y=0
|
||||
|
||||
#loops through each podcast and parses out relevant information
|
||||
while y < x:
|
||||
title = outline[y].title
|
||||
url = outline[y].xmlUrl
|
||||
artwork = outline[y].pr_artwork
|
||||
desc = outline[y].pr_desc
|
||||
|
||||
#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""" % (url, 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] != url:
|
||||
query = db.sql.text("""insert into Podcasts (userID, title, URL, artworkURL) values(%i, \"%s\", \"%s\", \"%s\") """ % (userID, title, url, artwork))
|
||||
db.con.execute(query)
|
||||
print("%s added" % title)
|
||||
else:
|
||||
print("%s already exists" % title)
|
||||
y=y+1
|
||||
|
||||
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
|
||||
|
||||
|
||||
def addFeed(userID):
|
||||
newURL = input("Enter Feed URL: ")
|
||||
count = 0
|
||||
|
||||
parsed = fp.parse(newURL)
|
||||
|
||||
title = parsed.feed.title
|
||||
artwork = 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)
|
||||
# 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]
|
||||
|
||||
# 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)
|
||||
count = count + 1
|
||||
else:
|
||||
print("%s already exists" % title)
|
||||
|
||||
def deleteFeed(userID):
|
||||
podcasts=[]
|
||||
y=0
|
||||
# grabs podcast urls from logged in user
|
||||
query = db.sql.text("""select podcastID, title from Podcasts where userID = %i""" % userID)
|
||||
results = db.con.execute(query).fetchall()
|
||||
|
||||
for each in results:
|
||||
print("%i. %s" % (y+1, results[y][1]))
|
||||
y=y+1
|
||||
val = input("Delete which podcast? ")
|
||||
|
||||
deletedID = results[val-1][1]
|
||||
print(deletedID)
|
||||
|
||||
query = db.sql.text("""delete * from Podcasts where podcastID = %i and userID = %i""" % (deletedID, userID))
|
||||
db.con.execute(query)
|
||||
|
||||
query = db.sql.text("""delete * from Shows where podcastID = %i and userID = %i""" % (deletedID, userID))
|
||||
db.con.execute(query)
|
||||
|
||||
print("%s has been deleted" % results[val][0])
|
||||
|
||||
11
database.py
11
database.py
@@ -1,11 +0,0 @@
|
||||
import sqlalchemy as sql
|
||||
|
||||
#db_URI = 'mysql+pymysql://pc:pc@192.168.86.198/Podcast'
|
||||
db_URI = 'mysql+pymysql://pc:pc@67.149.14.121:3306/Podcast'
|
||||
# db_URI = 'mysql+pymysql://pc:pc@dandembinski.duckdns.org:80/Podcast'
|
||||
|
||||
engine = sql.create_engine(db_URI)
|
||||
con = engine.connect()
|
||||
|
||||
metadata = sql.MetaData()
|
||||
|
||||
8
main.py
8
main.py
@@ -1,7 +1,6 @@
|
||||
import feedparser as fp
|
||||
from flask import Flask, jsonify
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from urllib.parse import unquote_plus
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@@ -56,7 +55,6 @@ def updateFeeds(userID):
|
||||
showCheck = []
|
||||
updatedShows = []
|
||||
|
||||
|
||||
# grabs podcast urls from logged in user
|
||||
pc = podcasts.query.filter_by(userID=userID).all()
|
||||
|
||||
@@ -85,7 +83,6 @@ def updateFeeds(userID):
|
||||
return jsonify(newShows=updatedShows)
|
||||
|
||||
|
||||
|
||||
@app.route('/addFeed/<int:userID>/<path:newURL>', methods=['PUT'])
|
||||
def addFeed(userID,newURL):
|
||||
|
||||
@@ -115,6 +112,7 @@ def addFeed(userID,newURL):
|
||||
else:
|
||||
return jsonify(message='Podcast already exists')
|
||||
|
||||
|
||||
@app.route('/listPodcasts/<int:userID>/', methods=['GET'])
|
||||
def listPodcasts(userID):
|
||||
output = []
|
||||
@@ -130,6 +128,7 @@ def listPodcasts(userID):
|
||||
|
||||
return jsonify(shows=output)
|
||||
|
||||
|
||||
@app.route('/register/<string:username>&<string:password>&<string:name>&<string:email>', methods=['POST'])
|
||||
def register(username, password, name, email):
|
||||
# checks to see if the username already exists
|
||||
@@ -143,9 +142,12 @@ 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)
|
||||
File diff suppressed because one or more lines are too long
@@ -1,7 +1,6 @@
|
||||
Click==7.0
|
||||
feedparser==5.2.1
|
||||
Flask==1.1.1
|
||||
Flask-API==2.0
|
||||
Flask-SQLAlchemy==2.4.1
|
||||
itsdangerous==1.1.0
|
||||
Jinja2==2.11.1
|
||||
|
||||
Reference in New Issue
Block a user