From d71970f4ce651ae8769b8e31f7dd5863a2f9984c Mon Sep 17 00:00:00 2001 From: hubobel Date: Fri, 1 Dec 2017 19:46:22 +0100 Subject: [PATCH] Es wird nun nur noch der entsprechende Tag abgefragt und gespeichert (Traffic) --- Lotto2SQL.py | 115 +++++++++++++++++++++++++++------------------------ 1 file changed, 62 insertions(+), 53 deletions(-) diff --git a/Lotto2SQL.py b/Lotto2SQL.py index 5a05c0c..684ecf1 100644 --- a/Lotto2SQL.py +++ b/Lotto2SQL.py @@ -1,66 +1,75 @@ import requests import pymysql +import time + 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() +wtag = time.strftime('%w') -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) +if wtag == 3: + 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() + +if wtag == 6: + 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() + +if wtag == 5: + 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() -connection.commit() cursor.close() connection.close()