Esempio n. 1
0
class App(MDApp):
    def build(self):
        A = ScreenManagement()
        A.current = 'main'

        #conn = sqlite3.connect(MYConfig().get_db_name())
        #c = conn.cursor()

        #c.close()
        #conn.close()

        # #Tabelle für Stocks anlegen
        #c.execute('CREATE TABLE IF NOT EXISTS STOCKS (Name, ISIN, Ticker)')
        #conn.commit()

        # #Tabelle für History anlegen
        # c.execute('CREATE TABLE IF NOT EXISTS Historie (Date, ISIN, Ticker, Open, High, Low, Close, AdjClose, Volume, Valuta)')
        # conn.commit()

        # #Tabelle für Div anlegen
        # c.execute('CREATE TABLE IF NOT EXISTS Dividends (DataDividendo, ISIN, Provento, Valuta, DataPagamento, TipoPagamento)')
        # conn.commit()

        return A

    def on_start(self):
        self.my_config = MYConfig()
        self.my_stocks = myStocks()
        self.borsaitaliana = BorsaItaliana()
        self.yahoo = YahooAPI()
        self.init_stocks_ist()

        # Backup Database
        if path.exists(self.my_config.get_db_name()):
            shutil.copyfile(
                self.my_config.get_db_name(),
                self.my_config.get_db_name().replace(
                    ".db", "_" + date.today().strftime("%Y%m%d") + ".db"))

    def init_stocks_ist(self):
        self.root.get_screen('main').ids.main_list.clear_widgets()
        for stock in self.my_stocks.get_stocks():
            self.neue_speise_zeile = TwoLineAvatarIconListItem(
                text=stock[0],
                secondary_text=str(stock[1]),
                #on_touch_up=self.test
            )
            self.neue_speise_zeile.bind(on_press=self.list_item_click)

            self.root.get_screen('main').ids.main_list.add_widget(
                self.neue_speise_zeile)

    def list_item_click(self, listitem):
        self.my_stocks.set_current_stock_isin(listitem.secondary_text)
        print(listitem.secondary_text)

        self.root.get_screen('div_details').ids.div_detail_list.clear_widgets()
        for i, row in self.borsaitaliana.get_all_dividends().iterrows():
            #print(f"{row['DataPagamento']}")
            if f"{row['ISIN']}" == self.my_stocks.get_current_stock_isin():
                self.neue_div_zeile = TwoLineAvatarIconListItem(
                    text=f"{row['Provento']}",
                    secondary_text=f"{row['DataPagamento']}",
                    #on_touch_up=self.test
                )
                #self.neue_div_zeile.bind(on_press=self.list_item_click)

                self.root.get_screen(
                    'div_details').ids.div_detail_list.add_widget(
                        self.neue_div_zeile)

        self.root.current = "div_details"
        self.root.transition.direction = "left"

    def nav_main(self):
        self.root.current = "main"
        self.root.transition.direction = "right"

    def get_date(self, date, start):
        '''
        :type date: <class 'datetime.date'>
        '''
        self.root.get_screen('main').ids.dtEnd.text = str(date)
        print(date)

    def show_date_picker_start(self):
        date_dialog = MDDatePicker(callback=self.get_date)
        date_dialog.open()

    def call_ticker(self):
        dh = self.yahoo
        now = datetime.datetime.strptime(
            self.root.get_screen('main').ids.dtEnd.text, "%Y-%m-%d"
        )  #datetime.datetime(2021, 1, 28)    # get data up to 6/28/2020
        then = datetime.datetime.strptime(
            self.root.get_screen('main').ids.dtStart.text, "%Y-%m-%d"
        )  #datetime.datetime(2020, 1, 1)        # get data from 01/01/2020
        df = dh.get_ticker_data(self.my_stocks.get_current_stock_ticker(),
                                then, now)
        print(df)

    def call_div(self):
        dh = self.borsaitaliana
        print(dh.count())
        df = dh.get_new_ticker_div(self.my_stocks.get_current_stock_isin())
        print(dh.count())
        print(df.count()[0])
        #print(dh.load())

    def call_all_ticker(self):
        dh = self.yahoo
        now = datetime.datetime.strptime(
            self.root.get_screen('main').ids.dtEnd.text, "%Y-%m-%d"
        )  #datetime.datetime(2021, 1, 28)    # get data up to 6/28/2020
        then = datetime.datetime.strptime(
            self.root.get_screen('main').ids.dtStart.text, "%Y-%m-%d"
        )  #datetime.datetime(2020, 1, 1)        # get data from 01/01/2020
        df = dh.get_ticker_data(
            self.root.get_screen('main').ids.txt_ticker.text, then, now)
        print(df)

    def call_all_div(self):
        dh = self.borsaitaliana
        for stock in self.my_stocks.get_stocks():
            df = dh.get_new_ticker_div(
                self.my_stocks.get_isin_from_name(stock[0]))
            try:
                print(df.count()[0])
            except:
                pass
        #print(dh.load())

    def print_all_div(self):
        dh = self.borsaitaliana
        df = dh.get_all_dividends()
        print(df)
        #print(dh.load())

    def set_csv_path(self):
        self.my_config.set_csv_path(
            self.root.get_screen('main').ids.txt_ticker.text)
        print(self.my_config.get_csv_path())

    def save_div_csv_div(self):
        dh = self.borsaitaliana
        dh.save_to_csv(self.my_config.get_csv_path() + "div_" +
                       date.today().strftime("%Y%m%d") + ".csv")
        pass

    def test_1(self):
        print(self.my_stocks.get_current_stock_isin())
        print(self.my_stocks.get_current_stock_name())
        #self.root.get_screen('main').ids.btn_test_1.text= "Save All Div ("+str(self.borsaitaliana.get_all_dividends().count()[0])+")"

    def test_2(self):
        pass

    def test_3(self):
        pass

    def test_4(self):
        pass
Esempio n. 2
0
class MainApp(MDApp):
    def on_start(self):
        # Set colors
        self.theme_cls.primary_palette = 'Blue'
        self.active_tab = "Speisen"

        self.kochbuch = Kochbuch("Kochbuch")
        self.lager = Lager("Lager")

        self.lade_speisen()
        self.lade_zutaten()

    def build(self):
        A = ScreenManagement()
        A.current = 'main'

        return A

    def on_tab_switch(self, instance_tabs, instance_tab, instance_tab_label,
                      tab_text):
        self.active_tab = tab_text
        #instance_tab.ids.label.text = tab_text
        return

    def lade_speisen(self):
        self.root.get_screen('main').ids.speisen_list.clear_widgets()
        for speise in self.kochbuch.get_speisen():
            self.add_new_speise(speise)

    def lade_zutaten(self):
        self.root.get_screen('main').ids.zutaten_list.clear_widgets()
        for zutat in self.lager.get_zutaten():
            self.add_new_zutat(zutat)

    def lade_speisen_zutaten(self, speise_guid):
        print("lade_speisen_zutaten: " + speise_guid)
        self.root.get_screen(
            'edit_speise').ids.edit_speise_zutaten_list.clear_widgets()
        speise = self.kochbuch.get_speise(speise_guid)
        print("Zutaten in Speise: " + str(len(speise.get_zutaten())))
        for zutat in speise.get_zutaten():
            self.new_zutat_zeile = TwoLineAvatarIconListItem(
                text=zutat.get_name(), secondary_text=zutat.get_guid())
            self.new_zutat_zeile.bind(on_press=self.list_item_click_speise)
            self.root.get_screen(
                'edit_speise').ids.edit_speise_zutaten_list.add_widget(
                    self.new_zutat_zeile)

    def save_speise(self):
        self.kochbuch.get_speise(
            self.root.get_screen('edit_speise').ids.sp_guid.text).set_name(
                self.root.get_screen('edit_speise').ids.sp_name.text)
        self.lade_speisen()
        self.root.current = "main"
        self.root.transition.direction = "right"

    def save_zutat(self):
        zutat = self.lager.get_zutat(
            self.root.get_screen('edit_zutat').ids.zt_guid.text)
        zutat.set_name(self.root.get_screen('edit_zutat').ids.zt_name.text)
        zutat.set_einheit(
            self.root.get_screen('edit_zutat').ids.zt_einheit.text)
        zutat.set_preis(self.root.get_screen('edit_zutat').ids.zt_preis.text)
        zutat.set_menge(self.root.get_screen('edit_zutat').ids.zt_menge.text)
        zutat.set_mindest(
            self.root.get_screen('edit_zutat').ids.zt_mindest.text)

        self.lade_zutaten()
        self.root.current = "main"
        self.root.transition.direction = "right"

    def save_speise_zutat(self):
        speise_guid = self.root.get_screen(
            'edit_speise_zutat').ids.zt_speise_guid.text
        zutat_guid = self.root.get_screen('edit_speise_zutat').ids.zt_guid.text

        zutat = self.kochbuch.get_speise(speise_guid).get_zutat(zutat_guid)
        zutat.set_name(
            self.root.get_screen('edit_speise_zutat').ids.zt_name.text)
        zutat.set_einheit(
            self.root.get_screen('edit_speise_zutat').ids.zt_einheit.text)
        zutat.set_preis(
            self.root.get_screen('edit_speise_zutat').ids.zt_preis.text)
        zutat.set_menge(
            self.root.get_screen('edit_speise_zutat').ids.zt_menge.text)
        zutat.set_mindest(
            self.root.get_screen('edit_speise_zutat').ids.zt_mindest.text)

        #        self.lade_speise_zutaten()
        self.root.current = "edit_speise"
        self.root.transition.direction = "right"

    def add_new_speise(self, new_speise):
        #print("Ok!")
        #self.speisen.append(new_speise)

        self.neue_speise_zeile = TwoLineAvatarIconListItem(
            text=new_speise.name,
            secondary_text=str(new_speise.get_guid()),
            #on_touch_up=self.test
        )
        self.neue_speise_zeile.bind(on_press=self.list_item_click)

        self.root.get_screen('main').ids.speisen_list.add_widget(
            self.neue_speise_zeile)

    def add_new_zutat(self, new_zutat):
        #print("Ok!")
        self.new_zutat_zeile = TwoLineAvatarIconListItem(
            text=new_zutat.name, secondary_text=str(new_zutat.get_guid()))
        self.new_zutat_zeile.bind(on_press=self.list_item_click)

        self.root.get_screen('main').ids.zutaten_list.add_widget(
            self.new_zutat_zeile)

    def add_new_speise_zutat(self):
        print(self.root.get_screen('edit_speise').ids.sp_guid.text)
        new_zutat = Zutat("Neue Zutat", "", "", "", "")
        self.new_zutat_zeile = TwoLineAvatarIconListItem(
            text=new_zutat.name, secondary_text=str(new_zutat.get_guid()))
        self.new_zutat_zeile.bind(on_press=self.list_item_click_speise)

        self.kochbuch.get_speise(
            self.root.get_screen('edit_speise').ids.sp_guid.text).add_zutat(
                new_zutat)
        self.root.get_screen(
            'edit_speise').ids.edit_speise_zutaten_list.add_widget(
                self.new_zutat_zeile)

    def add_new(self):
        if self.active_tab == "Speisen":
            neue_speise = Speise("Omlette NEW!")
            self.kochbuch.add_speise(neue_speise)
            self.add_new_speise(neue_speise)
        else:
            neue_zutat = Zutat("Zutat NEW!", "", "", "", "")
            self.lager.add_zutat(neue_zutat)
            self.add_new_zutat(neue_zutat)

    def list_item_click(self, listItem):
        if self.root.current == "main":
            if self.active_tab == "Speisen":
                print("list_item_click Speise: ", listItem.secondary_text)

                speise = self.kochbuch.get_speise(listItem.secondary_text)
                self.root.get_screen(
                    'edit_speise').ids.sp_name.text = speise.get_name()
                self.root.get_screen(
                    'edit_speise').ids.sp_guid.text = speise.get_guid()

                self.lade_speisen_zutaten(listItem.secondary_text)

                self.root.current = "edit_speise"
                self.root.transition.direction = "left"

            if self.active_tab == "Zutaten":
                print("Zutat: ", listItem.secondary_text)

                zutat = self.lager.get_zutat(listItem.secondary_text)
                self.root.get_screen(
                    'edit_zutat').ids.zt_name.text = zutat.get_name()
                self.root.get_screen(
                    'edit_zutat').ids.zt_guid.text = zutat.get_guid()
                self.root.get_screen(
                    'edit_zutat').ids.zt_einheit.text = zutat.get_einheit()
                self.root.get_screen(
                    'edit_zutat').ids.zt_preis.text = zutat.get_preis()
                self.root.get_screen(
                    'edit_zutat').ids.zt_mindest.text = zutat.get_mindest()
                self.root.get_screen(
                    'edit_zutat').ids.zt_menge.text = zutat.get_menge()

                self.root.current = "edit_zutat"
                self.root.transition.direction = "left"

    def list_item_click_speise(self, listItem):
        print("Zutat: ", listItem.secondary_text)

        speise_guid = self.root.get_screen('edit_speise').ids.sp_guid.text
        zutat = self.kochbuch.get_speise(speise_guid).get_zutat(
            listItem.secondary_text)
        self.root.get_screen(
            'edit_speise_zutat').ids.zt_name.text = zutat.get_name()
        self.root.get_screen(
            'edit_speise_zutat').ids.zt_speise_guid.text = speise_guid
        self.root.get_screen(
            'edit_speise_zutat').ids.zt_guid.text = zutat.get_guid()
        self.root.get_screen(
            'edit_speise_zutat').ids.zt_einheit.text = zutat.get_einheit()
        self.root.get_screen(
            'edit_speise_zutat').ids.zt_preis.text = zutat.get_preis()
        self.root.get_screen(
            'edit_speise_zutat').ids.zt_mindest.text = zutat.get_mindest()
        self.root.get_screen(
            'edit_speise_zutat').ids.zt_menge.text = zutat.get_menge()

        self.root.current = "edit_speise_zutat"
        self.root.transition.direction = "left"

    def del_current(self):
        if self.root.current == "edit_speise":
            print(self.root.get_screen('edit_speise').ids.sp_guid.text)
            self.kochbuch.del_speise(
                self.root.get_screen('edit_speise').ids.sp_guid.text)
            self.kochbuch.save()
            self.lade_speisen()

            self.root.current = "main"
            self.root.transition.direction = "right"

        if self.root.current == "edit_zutat":
            zt_guid = self.root.get_screen('edit_zutat').ids.zt_guid.text
            print(zt_guid)
            self.lager.del_zutat(zt_guid)
            self.lager.save()
            self.lade_zutaten()

            self.root.current = "main"
            self.root.transition.direction = "right"

        if self.root.current == "edit_speise_zutat":
            speise_guid = self.root.get_screen(
                'edit_speise_zutat').ids.zt_speise_guid.text
            zutat_guid = self.root.get_screen(
                'edit_speise_zutat').ids.zt_guid.text
            self.kochbuch.get_speise(speise_guid).del_zutat(zutat_guid)
            self.kochbuch.save()
            self.lade_speisen_zutaten(speise_guid)

            self.root.current = "edit_speise"
            self.root.transition.direction = "right"

    def tb_option_click(self):
        # dropdown = DropDown()
        # for index in range(10):

        #     # Adding button in drop down list
        #     btn = Button(text ='Value % d' % index, size_hint_y = None, height = 40)

        #     # binding the button to show the text when selected
        #     btn.bind(on_release = lambda btn: dropdown.select(btn.text))

        #     # then add the button inside the dropdown
        #     dropdown.add_widget(btn)
        # dropdown.bind(on_select = lambda instance, x: setattr(mainbutton, 'text', x))
        # runTouchApp(self.root.get_screen('edit_zutat'))

        if self.root.current == "main":
            print("Konfig!")
            self.kochbuch.save()
            self.lager.save()

    def sort_speisen(self):
        print("sort")
        #self.root.ids.speisen_list.so

    def nav_main(self):
        self.root.current = "main"
        self.root.transition.direction = "right"

    def nav_speise_edit(self):
        self.root.current = "edit_speise"
        self.root.transition.direction = "right"