Ausgabe, wieviel DB Einträge getätigt wurden
This commit is contained in:
parent
bf53722a30
commit
294c2bf3b2
1 changed files with 12 additions and 8 deletions
|
|
@ -1,7 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import bs4 as bs
|
import bs4 as bs
|
||||||
import requests
|
import requests
|
||||||
import time
|
|
||||||
import pymysql
|
import pymysql
|
||||||
|
|
||||||
connection = pymysql.connect(db="hubobel",
|
connection = pymysql.connect(db="hubobel",
|
||||||
|
|
@ -10,14 +9,16 @@ connection = pymysql.connect(db="hubobel",
|
||||||
host='10.0.1.59',charset='utf8')
|
host='10.0.1.59',charset='utf8')
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
try:
|
try:
|
||||||
cursor.execute("""CREATE TABLE test (
|
cursor.execute("""CREATE TABLE Filosofie (
|
||||||
nr INTEGER, Filosophiefact TEXT)""")
|
Nr INTEGER, Filosofie TEXT)""")
|
||||||
except:
|
except:
|
||||||
print ('weiter')
|
print ('weiter')
|
||||||
sql = "SELECT * FROM test ORDER BY nr DESC"
|
sql = "SELECT * FROM Filosofie ORDER BY Nr DESC"
|
||||||
resp = cursor.execute(sql)
|
resp = cursor.execute(sql)
|
||||||
|
resp3=resp
|
||||||
|
print(resp)
|
||||||
ergebniss=''
|
ergebniss=''
|
||||||
|
new=0
|
||||||
|
|
||||||
requests.packages.urllib3.disable_warnings()
|
requests.packages.urllib3.disable_warnings()
|
||||||
sauce = requests.get('https://www.swr3.de/wraps/fun/filosofie/neu.php?id=11', verify=False)
|
sauce = requests.get('https://www.swr3.de/wraps/fun/filosofie/neu.php?id=11', verify=False)
|
||||||
|
|
@ -38,20 +39,23 @@ while start <= anzahl:
|
||||||
filosophie=(i.text)
|
filosophie=(i.text)
|
||||||
print(filosophie)
|
print(filosophie)
|
||||||
print(start,' von ',anzahl)
|
print(start,' von ',anzahl)
|
||||||
sql = "INSERT INTO `test`(`nr`, `Filosophiefact`) VALUES ('" + str(start) + "','" + filosophie + "')"
|
sql = "INSERT INTO `Filosofie`(`Nr`, `Filosofie`) VALUES ('" + str(start) + "','" + filosophie + "')"
|
||||||
sql_q = "SELECT * FROM test WHERE Filosophiefact like '%" + str(filosophie) + "%'"
|
sql_q = "SELECT * FROM Filosofie WHERE Filosofie like '%" + str(filosophie) + "%'"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
resp = cursor.execute(sql_q)
|
resp = cursor.execute(sql_q)
|
||||||
if resp == 0:
|
if resp == 0:
|
||||||
try:
|
try:
|
||||||
resp = cursor.execute(sql)
|
resp = cursor.execute(sql)
|
||||||
|
new +=1
|
||||||
except:
|
except:
|
||||||
print('Es gab ein Problem beim Schreiben des facts in die DB')
|
print('Es gab ein Problem beim Schreiben des facts in die DB')
|
||||||
except:
|
except:
|
||||||
None
|
None
|
||||||
connection.commit()
|
connection.commit()
|
||||||
start +=1
|
start +=1
|
||||||
|
sql = "SELECT * FROM Filosofie ORDER BY Nr DESC"
|
||||||
|
resp2 = cursor.execute(sql)
|
||||||
|
print('Es wurden ', int(resp2)-int(resp3), ' neue Filosofien der DB hinzugefügt.')
|
||||||
cursor.close()
|
cursor.close()
|
||||||
connection.close()
|
connection.close()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue