From 4f37bfdceb7902750d76e6b3427af5719abf8c77 Mon Sep 17 00:00:00 2001 From: hubobel Date: Fri, 1 Dec 2017 19:28:19 +0100 Subject: [PATCH] =?UTF-8?q?Tr=C3=A4gt=20die=20Lottozahlen=20in=20eine=20SQ?= =?UTF-8?q?l=20Datenbank=20ein?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lotto2SQL.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Lotto2SQL.py diff --git a/Lotto2SQL.py b/Lotto2SQL.py new file mode 100644 index 0000000..5a05c0c --- /dev/null +++ b/Lotto2SQL.py @@ -0,0 +1,66 @@ +import requests +import pymysql + +connection = pymysql.connect(db="hubobel", + user="hubobel", + passwd="polier2003", + host='10.0.1.59',charset='utf8') +cursor = connection.cursor() +try: + cursor.execute("""CREATE TABLE mittwoch ( + datum Text, z1 INTEGER, z2 INTEGER, z3 INTEGER, z4 INTEGER, z5 INTEGER, z6 INTEGER, sz INTEGER, super6 INTEGER, spiel77 INTEGER)""") +except: + None +url_zitat = 'http://api.hubobel.de/lotto/Mittwoch' +resp_zitat = requests.get(url_zitat) +data_zitat = resp_zitat.json() +data=data_zitat[1] +sql = "INSERT INTO `mittwoch`(`datum`, `z1`, `z2`, `z3`, `z4`, `z5`, `z6`, `sz`, `super6`, `spiel77` ) VALUES " \ + "('"+str(data['Datum'])+"','"+str(data['Z1'])+"','"+str(data['Z2'])+"','"+str(data['Z3'])+"','"+\ + str(data['Z4'])+"','"+str(data['Z5'])+"','"+str(data['Z6'])+"','"+str(data['Superzahl'])+\ + "','"+str(data['Super6'])+"','"+str(data['Spiel77'])+"')" +sql_q = "SELECT * FROM mittwoch WHERE datum like '%" + data['Datum'] + "%'" +resp = cursor.execute(sql_q) +if resp == 0: + cursor.execute(sql) +connection.commit() + +try: + cursor.execute("""CREATE TABLE samstag ( + datum Text, z1 INTEGER, z2 INTEGER, z3 INTEGER, z4 INTEGER, z5 INTEGER, z6 INTEGER, sz INTEGER, super6 INTEGER, spiel77 INTEGER)""") +except: + None +url_zitat = 'http://api.hubobel.de/lotto/Samstag' +resp_zitat = requests.get(url_zitat) +data_zitat = resp_zitat.json() +data=data_zitat[1] +sql = "INSERT INTO `samstag`(`datum`, `z1`, `z2`, `z3`, `z4`, `z5`, `z6`, `sz`, `super6`, `spiel77`) VALUES" \ + " ('"+str(data['Datum'])+"','"+str(data['Z1'])+"','"+str(data['Z2'])+"','"+str(data['Z3'])+\ + "','"+str(data['Z4'])+"','"+str(data['Z5'])+"','"+str(data['Z6'])+"','"+str(data['Superzahl'])+\ + "','"+str(data['Super6'])+"','"+str(data['Spiel77'])+"')" +sql_q = "SELECT * FROM samstag WHERE datum like '%" + data['Datum'] + "%'" +resp = cursor.execute(sql_q) +if resp == 0: + cursor.execute(sql) +connection.commit() + +try: + cursor.execute("""CREATE TABLE euro ( + datum Text, z1 INTEGER, z2 INTEGER, z3 INTEGER, z4 INTEGER, z5 INTEGER, sz1 INTEGER, sz2 INTEGER )""") +except: + None +url_zitat = 'http://api.hubobel.de/lotto/Euro' +resp_zitat = requests.get(url_zitat) +data_zitat = resp_zitat.json() +data=data_zitat[1] +sql = "INSERT INTO `euro`(`datum`, `z1`, `z2`, `z3`, `z4`, `z5`, `sz1`, `sz2`) VALUES" \ + " ('"+str(data['Datum'])+"','"+str(data['Z1'])+"','"+str(data['Z2'])+"','"+str(data['Z3'])+\ + "','"+str(data['Z4'])+"','"+str(data['Z5'])+"','"+str(data['Superzahl1'])+"','"+str(data['Superzahl2'])+"')" +sql_q = "SELECT * FROM euro WHERE datum like '%" + data['Datum'] + "%'" +resp = cursor.execute(sql_q) +if resp == 0: + cursor.execute(sql) + +connection.commit() +cursor.close() +connection.close()