|
|
|
@ -1,23 +1,20 @@
|
|
|
|
|
import requests, json, os, random
|
|
|
|
|
from kivy.app import App
|
|
|
|
|
from kivy.uix.label import Label
|
|
|
|
|
from kivy.uix.boxlayout import BoxLayout
|
|
|
|
|
from kivy.graphics import Rectangle
|
|
|
|
|
from kivy.uix.image import Image
|
|
|
|
|
from kivy.uix.button import Button
|
|
|
|
|
from kivy.core.window import Window
|
|
|
|
|
from kivymd.app import MDApp
|
|
|
|
|
from kivymd.uix.button import MDRectangleFlatButton
|
|
|
|
|
import requests, json, os, random
|
|
|
|
|
|
|
|
|
|
# API key
|
|
|
|
|
api_key="A RECUPERER DU SERVEUR API"
|
|
|
|
|
api_url = "https://citations.domaine.tld/api/citations/random"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MainApp(MDApp):
|
|
|
|
|
def build(self):
|
|
|
|
|
return MainWidget()
|
|
|
|
|
|
|
|
|
|
# class widget
|
|
|
|
|
class MainWidget(BoxLayout):
|
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
|
super(MainWidget, self).__init__(orientation='vertical', **kwargs)
|
|
|
|
@ -29,7 +26,6 @@ class MainWidget(BoxLayout):
|
|
|
|
|
self.add_widget(self.quote_label)
|
|
|
|
|
|
|
|
|
|
# bouton
|
|
|
|
|
#button = Button(text='Recharger', size_hint=(None, None), size=(300, 100), pos_hint={'center_x': 0.5, 'center_y': 0.1})
|
|
|
|
|
button = MDRectangleFlatButton(text='Recharger', size_hint=(None, None), size=(300, 100), pos_hint={'center_x': 0.5, 'center_y': 0.1}, line_color="white", text_color="white")
|
|
|
|
|
button.bind(on_press=self.load_citation)
|
|
|
|
|
self.add_widget(button)
|
|
|
|
@ -40,7 +36,7 @@ class MainWidget(BoxLayout):
|
|
|
|
|
|
|
|
|
|
# for button
|
|
|
|
|
def load_citation(self, instance=None):
|
|
|
|
|
quote = get_citation()
|
|
|
|
|
quote = get_citation(api_url)
|
|
|
|
|
auteur = quote[1]
|
|
|
|
|
citation = split_string(quote[0], 40)
|
|
|
|
|
|
|
|
|
@ -53,8 +49,8 @@ class MainWidget(BoxLayout):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# fonction pour récupérer la citation de l'API
|
|
|
|
|
def get_citation():
|
|
|
|
|
api_url = "https://citations.gregandev.fr/api/citations/random"
|
|
|
|
|
def get_citation(api_url):
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
headers = {
|
|
|
|
|
"API-Key": api_key
|
|
|
|
|