diff --git a/REST_APIv2.py b/REST_APIv2.py index 6283162..a510ba5 100644 --- a/REST_APIv2.py +++ b/REST_APIv2.py @@ -1,28 +1,36 @@ import random -from flask import Flask, jsonify,make_response -from flask import request +from flask import Flask, jsonify, make_response +from flask import request, send_file import pymysql import bs4 as bs import requests as req +import datetime +from selenium import webdriver +from time import sleep +from selenium.webdriver.chrome.options import Options +import time +import json app = Flask(__name__) + def Update(): connection = pymysql.connect(db="hubobel", - user="hubobel", - passwd="polier2003", - host='10.0.1.59',charset='utf8') + user="hubobel", + passwd="polier2003", + host='10.0.1.59', charset='utf8') cursor = connection.cursor() - sql="SELECT * FROM facts" - resp=cursor.execute(sql) - x=cursor.fetchall() - fact=dict(x) + sql = "SELECT * FROM facts" + resp = cursor.execute(sql) + x = cursor.fetchall() + fact = dict(x) cursor.close() connection.close() - a=len(fact) - return fact,a -def Lotto(): + a = len(fact) + return fact, a + +def Lotto(): connection = pymysql.connect(db="hubobel", user="hubobel", passwd="polier2003", @@ -84,36 +92,65 @@ def Lotto(): connection.commit() cursor.close() connection.close() - return ZahlenMittwoch,ZahlenEuro,ZahlenSamstag + return ZahlenMittwoch, ZahlenEuro, ZahlenSamstag + + def Lottoaktuell(): + # req.packages.urllib3.disable_warnings() + # sauce = req.get('https://www.eurojackpot.org/gewinnzahlen/', verify=False) + # soup = bs.BeautifulSoup(sauce.text, 'lxml') + # + # zahlen = [] + # ergebniss = [] + # ZahlenEuro = {'Datum': '', 'Z1': '', 'Z2': '', 'Z3': '', 'Z4': '', 'Z5': '', 'Eurozahl1': '', 'Eurozahl2': ''} + # a = 1 + # + # datum = soup.find_all('time') + # tag = [] + # for i in datum: + # tag.append(i.text) + # for li in soup.find_all('li'): + # zahlen.append(li.text) + # for i in zahlen[0:7]: + # ergebniss.append(int(i)) + # ergebniss.append(tag[1]) + # while a != 6: + # ZahlenEuro['Z' + str(a)] = ergebniss[a - 1] + # a = a + 1 + # + # + # + # ende = (ergebniss[7].find('- Freitag')) + # Datum=ergebniss[7] + # ZahlenEuro['Datum'] = Datum[:ende-1] + # ZahlenEuro['Eurozahl1'] = ergebniss[5] + # ZahlenEuro['Eurozahl2'] = ergebniss[6] req.packages.urllib3.disable_warnings() - sauce = req.get('https://www.eurojackpot.org/gewinnzahlen/', verify=False) + sauce = req.get( + 'https://www.sachsenlotto.de/portal/zahlen-quoten/gewinnzahlen/eurojackpot-gewinnzahlen/eurojackpot-gewinnzahlen.jsp', + verify=False) soup = bs.BeautifulSoup(sauce.text, 'lxml') zahlen = [] ergebniss = [] ZahlenEuro = {'Datum': '', 'Z1': '', 'Z2': '', 'Z3': '', 'Z4': '', 'Z5': '', 'Eurozahl1': '', 'Eurozahl2': ''} a = 1 - datum = soup.find_all('time') - tag = [] - for i in datum: - tag.append(i.text) - for li in soup.find_all('li'): - zahlen.append(li.text) - for i in zahlen[0:7]: - ergebniss.append(int(i)) - ergebniss.append(tag[1]) - while a != 6: - ZahlenEuro['Z' + str(a)] = ergebniss[a - 1] - a = a + 1 + source = soup.find_all('span', + class_='sl-statistic-number-circle-container-filled col-lg-1 col-md-1 col-sm-1 col-xs-1') + for i in source: + zahlen.append(i.text) + while a <= 5: + ZahlenEuro['Z' + str(a)] = int(zahlen[a - 1]) + a += 1 + ZahlenEuro['Eurozahl1'] = zahlen[5] + ZahlenEuro['Eurozahl2'] = zahlen[6] + print(ZahlenEuro) - - - ende = (ergebniss[7].find('- Freitag')) - Datum=ergebniss[7] - ZahlenEuro['Datum'] = Datum[:ende-1] - ZahlenEuro['Eurozahl1'] = ergebniss[5] - ZahlenEuro['Eurozahl2'] = ergebniss[6] + source = soup.find_all('h3', style='color: white') + for i in source: + datum = i.text + start = (datum.find('Freitag,')) + 9 + ZahlenEuro['Datum'] = datum[start:] req.packages.urllib3.disable_warnings() sauce = req.get('https://www.lotto24.de/webshop/product/lottonormal/result', verify=False) @@ -157,40 +194,102 @@ def Lottoaktuell(): Lottozahlen['Super6'] = Super6 Lottozahlen['Datum'] = date[start:ende] - return Lottozahlen,ZahlenEuro + return Lottozahlen, ZahlenEuro + + +def TV(mode): + if mode == 0: + mode = 'jetzt' + range = 7 + if mode == 1: + mode = 'abends' + range = 7 + if mode == 2: + mode = 'fernsehprogramm-nachts' + range = 7 + if mode == 3: + mode = 'jetzt' + range = 1 + + Sendungen = {} + x = 1 + while x <= range: + sauce = req.get('http://www.tvspielfilm.de/tv-programm/sendungen/' + mode + '.html?page=' + str(x), + verify=False) + soup = bs.BeautifulSoup(sauce.text, 'lxml') + + sender_source = soup.find_all('td', class_='programm-col1') + sendungen_source = soup.find_all('strong') + + Sender = [] + Sendung = [] + + for i in sendungen_source: + Sendung.append(i.text) + for i in sender_source: + text = i.text + text = text.replace('\n', '') + text = text.replace(' ', '') + Sender.append(text) + Sendung.pop(0) # erstes Element des Listenelements 'Sendung' wird entfernt + programm = {} + a = 0 + b = 0 + + while a < len(Sender): + programm['Uhrzeit'] = Sendung[b] + programm['Titel'] = Sendung[b + 1] + Sendungen[Sender[a]] = {} + Sendungen[Sender[a]].update(programm) + a += 1 + b += 2 + x += 1 + liste = [] + for i in Sendungen: + liste.append(i) + Sendungen['Senderliste'] = liste + return Sendungen + @app.route('/lotto', methods=['GET']) def get_lotto(): - Mit,EUR,Sam=Lotto() - return jsonify('Hinweis: Alle Angaben ohne Gewaehr auf Richtigkeit:',Mit,EUR,Sam) + Mit, EUR, Sam = Lotto() + return jsonify('Hinweis: Alle Angaben ohne Gewaehr auf Richtigkeit:', Mit, EUR, Sam) + @app.route('/lotto/Samstag', methods=['GET']) def get_lottoSam(): - Mit,EUR,Sam=Lotto() - return jsonify('Hinweis: Alle Angaben ohne Gewaehr auf Richtigkeit:',Sam) + Mit, EUR, Sam = Lotto() + return jsonify('Hinweis: Alle Angaben ohne Gewaehr auf Richtigkeit:', Sam) + @app.route('/lotto/Mittwoch', methods=['GET']) def get_lottoMit(): - Mit,EUR,Sam=Lotto() - return jsonify('Hinweis: Alle Angaben ohne Gewaehr auf Richtigkeit:',Mit) + Mit, EUR, Sam = Lotto() + return jsonify('Hinweis: Alle Angaben ohne Gewaehr auf Richtigkeit:', Mit) + @app.route('/lotto/Euro', methods=['GET']) def get_lottoEur(): - Mit,EUR,Sam=Lotto() - return jsonify('Hinweis: Alle Angaben ohne Gewaehr auf Richtigkeit:',EUR) + Mit, EUR, Sam = Lotto() + return jsonify('Hinweis: Alle Angaben ohne Gewaehr auf Richtigkeit:', EUR) + @app.route('/lotto/aktuell', methods=['GET']) def get_lottoAktuell(): - Lottozahlen,ZahlenEuro=Lottoaktuell() + Lottozahlen, ZahlenEuro = Lottoaktuell() + + return jsonify(Lottozahlen, ZahlenEuro) - return jsonify(Lottozahlen,ZahlenEuro) @app.errorhandler(404) def not_found(error): return make_response(jsonify({'error': 'Nicht unterstuetzt'}), 404) + + @app.route('/') def index(): - fact,a = Update() + fact, a = Update() return """ @@ -211,18 +310,34 @@ def index():
GET: api.hubobel.de/lotto/Samstag.....: Liefert die letzten Samstagszahlen (aus der Datenbank)
GET: api.hubobel.de/lotto/aktuell.....: Liefert die letzten Lottozahlen des Euro- und Mittwoch bzw.Samstagslotto (online jeweils neu ermittelt)
+GET: api.hubobel.de/bitcoin.....: Liefert die aktuellen Bitcoinkurse in EURO
+GET: api.hubobel.de/wetter.....: Liefert das aktuelle Wetter in Oggersheim
+GET: api.hubobel.de/sprit/'km'.....: Liefert die aktuellen Kraftstoffpreise im Umreis von 'km' Radius um 67071
+GET: api.hubobel.de/sprit/'Ort'.....: Liefert die aktuellen Kraftstoffpreise im 10km Radius + um den übergebenen Ort
+GET: api.hubobel.de/tv.....: Liefert das aktuelle TV Programm der Hauptsender
+GET: api.hubobel.de/tv/jetzt.....: Liefert das aktuelle TV Programm aller Sender
+GET: api.hubobel.de/tv/2015.....: Liefert das aktuelle TV Programm aller Sender um 20.15Uhr
+GET: api.hubobel.de/tv/2200.....: Liefert das aktuelle TV Programm aller Sender um 22.00Uhr
+GET: api.hubobel.de/filosophie.....: Liefert Filosophie des SWR3 zurück
+GET: api.hubobel.de/shoot/'www.example.de'.....: Liefert Screenshot von example.de zurück
+POST: api.hubobel.de/tv/check.....: Uebergabe von beliebigen Sendern als Liste - liefert Programm zurueck
POST: api.hubobel.de/lotto/6aus49/check.....: Uebergabe der 6+1 Zahlen als Liste - liefert Anzahl der Treffer zurueck
POST: api.hubobel.de/lotto/6aus49/check.....: Uebergabe der 5+2 Zahlen als Liste - liefert Anzahl der Treffer zurueck
...to be continued
- +