예제 #1
0
def checkNewEpisodes(response, in_video_id=None):
    #channelId = get_channel_id()
    #response = search_youtube(channelId)
    if in_video_id is None:
        epi_id = response["items"][0]["id"]["videoId"]
    else:
        epi_id = in_video_id
    epi_title = response["items"][0]["snippet"]["title"]
    epi_summary = response["items"][0]["snippet"]["description"]
    epi_pubdate = response["items"][0]["snippet"]["publishedAt"]
    playlist_id = get_playlist_id()
    video_url = getVideoLink(epi_id)
    epi_url = getEpisodelink(epi_id)
    epi_thumbnail_link = response["items"][0]["snippet"]["thumbnails"][
        "default"]["url"]

    downloader = Y2Mp3()
    db = connect.connect2db()
    cur = db.cursor()
    useDB(cur)

    res = cur.execute("SELECT epi_id FROM podcast WHERE epi_id = %s",
                      (epi_id, ))

    if not res:
        downloader.startDownload(video_url)
        downloaded = 1
        cur.execute(
            'INSERT INTO podcast (podcast_id, epi_id, epi_url, epi_title, epi_summary, epi_pub_date, epi_thumbnail_link, downloaded) VALUES ( "{}","{}","{}","{}","{}","{}","{}","{}")'
            .format(playlist_id, epi_id, epi_url, epi_title, epi_summary,
                    epi_pubdate, epi_thumbnail_link, downloaded))
        db.commit()

    print("downloaded and inserted to the database")
예제 #2
0
def server():

    #right now treating podcast id as playlist id
    playlist_id = get_playlist_id()

    db = connect.connect2db()
    cur = db.cursor()
    useDB(cur)

    p = create_podcast(
        "Zara Hat Kay", "Zara Hat Kay Description",
        "https://www.youtube.com/channel/UCaxR-D8FjZ-2otbU0_Y2grg")

    cur.execute(
        "SELECT * FROM podcast")  #WHERE podcast_id = %s", (playlist_id,))

    for round in cur:
        add_episodes(p, round)

    p.rss_file('templates/' + playlist_id + '.rss', minimize=True)

    rss_xml = render_template(playlist_id + '.rss')
    response = make_response(rss_xml)
    response.headers['Content-Type'] = 'application/rss+xml'
    return response
예제 #3
0
def deleteFromDB():
    playlist_id = get_playlist_id()
    print(playlist_id)
    db = connect.connect2db()
    cur = db.cursor()
    useDB(cur)

    cur.execute(
        """Delete from podcast where podcast_id = 'PLqvJuaAfjXbQZEZrIYkNHyd5JYW4p'"""
    )
    db.commit()
    #res = cur.execute("SELECT * FROM podcast WHERE podcast_id = %s", (playlist_id,))
    cur.execute("SELECT * FROM podcast")

    for round in cur:
        print(round)
예제 #4
0
    return group_research


def CreateUniqueIDForGroup(group_research, mycursor, connection):
    sql1 = "select MD5(%s);"
    sql2 = """update research_student
                set unique_id = %s
                where student_id like %s and
                tname like %s and
                research_title like %s and
                first_second like %s and
                semester like %s;
    """
    for g in group_research:
        unique_id = str("")
        for i in range(len(g)):
            unique_id += g[i][1]
        unique_id += str(g[0][2]) + str(g[0][3]) + str(g[0][4]) + str(g[0][8])
        mycursor.execute(sql1, (unique_id, ))
        md5 = mycursor.fetchone()
        for i in range(len(g)):
            mycursor.execute(
                sql2, (md5, g[i][1], g[i][2], g[i][3], g[i][4], g[i][8]))
            connection.commit()


if __name__ == "__main__":
    mycursor, connection = connect.connect2db()
    group_research = GetGroupFromDB(mycursor, connection)
    CreateUniqueIDForGroup(group_research, mycursor, connection)