From d9d9a1ffdfc1d885fc1162e2c6863fcbcbb3f126 Mon Sep 17 00:00:00 2001 From: Dan Dembinski Date: Wed, 19 Feb 2020 16:02:34 -0500 Subject: [PATCH] Added some basic logic to import OPML files into database. Broke some sql server settings into separate file. --- database.py | 9 +++++++++ main.py | 49 +++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 database.py diff --git a/database.py b/database.py new file mode 100644 index 0000000..d3310f0 --- /dev/null +++ b/database.py @@ -0,0 +1,9 @@ +import sqlalchemy as sql + +db_URI = 'mysql+pymysql://pc:pc@192.168.86.198/Podcast' +# db_URI = 'mysql+pymysql://pc:pc@dandembinski.duckdns.org:80/Podcast' + +engine = sql.create_engine(db_URI) +con = engine.connect() + +metadata = sql.MetaData() \ No newline at end of file diff --git a/main.py b/main.py index f9c9861..6eca6db 100644 --- a/main.py +++ b/main.py @@ -1,14 +1,51 @@ import opml +# import sqlalchemy as db +import database.py as db + + +def podcastImport (userID): + + + podcasts = db.Table('Users', db.metadata, autoload=True, autoload_with=db.engine) -def podcastImport (): outline = opml.parse("podcast_republic_podcasts.opml") x = len(outline) y=0 while y < x: - print(outline[y].title) - print(outline[y].xmlUrl) - print(outline[y].pr_artwork) - print(outline[y].pr_desc) - print() + title = outline[y].title + url = outline[y].xmlUrl + artwork = outline[y].py_artwork + desc = outline[y].pr_desc + query = """insert into """ + podcasts+""""(userID, title, URL, desc, artworkURL values (""" + userID + """,""" + title + """,""" + url + """,""" + desc + """,""" + artwork + """)""" + db.con.execute(query) y=y+1 + + +def login(): + username = 'dan' + password = 'password' + + + user = db.Table('Users', db.metadata, autoload=True, autoload_with=db.engine) + + query = db.text(""" select userID from """ + user + """ where username =""" + username) + result = db.con.execute(query).fetchone() + + db.con.close() + + return result + + +while True: + userID = None + + print("1. Login \n 2. Upload") + val = input(">>>") + if val == "1": + userID = login() + elif val == "2": + if userID is None or userID == '': + print("Please login first") + else: + podcastImport(userID)