diff --git a/teletext.py b/teletext.py index 2f35e58..285e5e7 100644 --- a/teletext.py +++ b/teletext.py @@ -1,8 +1,8 @@ import urllib3 from bs4 import BeautifulSoup -import textwrap import hashlib import sqlite3 +import time from sqlite3 import Error def create_conn(db_file): @@ -24,86 +24,99 @@ def create_table(conn, create_table_SQL): print(e) def insert_site(conn, site): - - sql = ''' INSERT INTO sites(hash,site,content) - VALUES(?,?,?) ''' + + sql = ''' INSERT INTO sites(unixtime,hash,tafel,description,title) + VALUES(?,?,?,?,?) ''' try: c = conn.cursor() c.execute(sql, site) conn.commit() return c.lastrowid except Error as e: - print(e) + err = e -def get_site(conn, site): - #sql = ''' SELECT content from sites WHERE site = ? ''' - sql = ''' SELECT content from sites ''' +def get_sites(conn): + sql = ''' SELECT description,title from sites order by unixtime desc limit 3 ''' try: c = conn.cursor() - #c.execute(sql, (site,)) c.execute(sql) rows = c.fetchall() return rows except Error as e: print(e) -def store_site(conn, site): - link = "http://www.ard-text.de/mobil/"+str(site) +def store_site(conn, tafel): + link = "http://www.ard-text.de/mobil/"+str(tafel) http = urllib3.PoolManager() r = http.request('GET', link) soup = BeautifulSoup(r.data, 'html.parser') - bla = soup.find('div', class_='std').text - bla_hash = hashlib.md5(bla.encode('utf-8')).hexdigest() - content = (bla_hash,site,bla) - insert_site(conn,content) + desc = soup.find('div', class_='std') + title = soup.find('h1') + if desc is not None: + if title is not None: + title = title.text.replace("