def test_get_latest_date_of_list(self):
     date_list = [
         date.string_to_date("09.08.2018"),
         date.string_to_date("09.05.2018"),
         date.string_to_date("09.11.2017"),
     ]
     current_date = date.string_to_date("11.10.2018")
     latest_date = parse.get_latest_date_of_list(date_list, current_date)
     self.assertEqual(date.string_to_date("09.08.2018"), latest_date)
Beispiel #2
0
 def test_get_last_days_of_month_2(self):
     asserted_last_months = [
         date.string_to_date("30.11.2018"),
         date.string_to_date("31.12.2018"),
         date.string_to_date("31.01.2019"),
         date.string_to_date("28.02.2019"),
     ]
     last_months = date.get_last_days_of_last_four_months(
         date.string_to_date("10.03.2019"))
     self.assertEqual(asserted_last_months, last_months)
Beispiel #3
0
 def test_get_last_days_of_month(self):
     asserted_last_months = [
         date.string_to_date("31.08.2018"),
         date.string_to_date("30.09.2018"),
         date.string_to_date("31.10.2018"),
         date.string_to_date("30.11.2018"),
     ]
     last_months = date.get_last_days_of_last_four_months(
         date.string_to_date("05.12.2018"))
     self.assertEqual(asserted_last_months, last_months)
Beispiel #4
0
def write_stock_history_to_db(stock_history, stock_uri, database=cst.DATABASE):
    with dataset.connect(database) as db:
        for item in stock_history:
            date_ = date.string_to_date(item[0])
            try:
                start = float(item[1].replace(".", "").replace(",", "."))
            except ValueError:
                logger.warning("ValueError: Missing start value for %s at %s" %
                               (stock_uri, str(date_)))
                start = None
            try:
                end = float(item[2].replace(".", "").replace(",", "."))
            except ValueError:
                logger.warning("ValueError: Missing end value for %s at %s" %
                               (stock_uri, str(date_)))
                end = None
            try:
                db[cst.TABLE_STOCKS_HISTORIES].insert(
                    dict(
                        AktienURI=stock_uri,
                        Datum=date_,
                        Eroeffnungswert=start,
                        Schlusswert=end,
                    ))
            except IntegrityError:
                pass
Beispiel #5
0
def write_index_history_to_db(index_history, index_uri, database=cst.DATABASE):
    with dataset.connect(database) as db:
        for item in index_history:
            date_ = date.string_to_date(item[0])
            try:
                start = float(item[1].replace(".", "").replace(",", "."))
            except ValueError:
                logger.warning("ValueError: Missing start value for %s at %s" %
                               (index_uri, str(date_)))
                start = None
            try:
                end = float(item[2].replace(".", "").replace(",", "."))
            except ValueError:
                logger.warning("ValueError: Missing end value for %s at %s" %
                               (index_uri, str(date_)))
                end = None
            try:
                db[cst.TABLE_INDEX_HISTORIES].insert(
                    dict(
                        IndexURI=index_uri,
                        Datum=date_,
                        Eroeffnungswert=start,
                        Schlusswert=end,
                    ))
            except IntegrityError:
                logger.warning(
                    "Write Index History to DB: Integrity Error with Item: %s"
                    % index_uri)
                pass
Beispiel #6
0
 def test_get_latest_date_from_stock_history_with_condition(self):
     asserted_latest_date = date.string_to_date("01.02.2019")
     actual_latest_date = db.get_item(
         table=cst.TABLE_STOCKS_HISTORIES,
         column="max(Datum)",
         condition=[cst.COLUMN_STOCK_URI, "Adidas-Aktie"],
         database=cst.TEST_DATABASE,
     )
     self.assertEqual(asserted_latest_date, actual_latest_date)
Beispiel #7
0
 def test_get_latest_date_from_index_history_with_condition(self):
     asserted_latest_date = date.string_to_date("08.03.2019")
     actual_latest_date = db.get_item(
         table=cst.TABLE_INDEX_HISTORIES,
         column="max(Datum)",
         condition=[cst.COLUMN_INDEX_URI, "dax"],
         database=cst.TEST_DATABASE,
     )
     self.assertEqual(asserted_latest_date, actual_latest_date)
Beispiel #8
0
 def test_get_quarterly_date(self):
     asserted_date = date.string_to_date("21.03.2019")
     self.assertEqual(
         asserted_date,
         db.get_item(
             table=cst.TABLE_STOCK_DATES,
             column=cst.COLUMN_DATE,
             condition=[cst.COLUMN_STOCK_URI, "ab_inbev-Aktie"],
             order=[cst.COLUMN_DATE, cst.DESC],
             database=cst.TEST_DATABASE,
         ),
     )
Beispiel #9
0
def get_last_quarterly_figures_date(soup, current_date=date.get_current_date()):
    """
    Calculates the newest, but in the past lying date, where a company event has
    been held. Returns a date-object
    :param soup:
    :return: date
    """
    result_td = soup.find(cst.HTML_H2, text=re.compile(cst.TEXT_BYGONE_DATES))
    parent_div = result_td.parent
    dates = parent_div.find_all(cst.HTML_TD, {cst.HTML_CLASS: cst.TEXT_TEXT_RIGHT})
    date_list = [date.string_to_date(date_.text.strip()) for date_ in dates]
    latest_date = get_latest_date_of_list(date_list, current_date=current_date)
    return latest_date
Beispiel #10
0
 def test_get_monthly_date_list(self):
     asserted_date_string_list = [
         "04.01.2019",
         "01.02.2019",
         "01.03.2019",
         "05.04.2019",
         "03.05.2019",
     ]
     asserted_date_list = [
         date.string_to_date(datestring)
         for datestring in asserted_date_string_list
     ]
     self.assertEqual(asserted_date_list,
                      date.get_first_friday_of_months(2019)[:5])
Beispiel #11
0
 def test_get_biweekly_date_list(self):
     asserted_date_string_list = [
         "04.01.2019",
         "18.01.2019",
         "01.02.2019",
         "15.02.2019",
         "01.03.2019",
         "15.03.2019",
         "05.04.2019",
         "19.04.2019",
         "03.05.2019",
         "17.05.2019",
     ]
     asserted_date_list = [
         date.string_to_date(datestring)
         for datestring in asserted_date_string_list
     ]
     self.assertEqual(asserted_date_list,
                      date.get_first_and_third_friday_of_months(2019)[:10])
 def test_get_last_quarterly_figures_date(self):
     soup = scrap.get_soup_code_from_file("data/bo_termine.html")
     result = parse.get_last_quarterly_figures_date(
         soup=soup, current_date=date.string_to_date("10.10.2018"))
     asserted_result = date.string_to_date("09.08.18")
     self.assertEqual(asserted_result, result)
Beispiel #13
0
 def test_get_closing_stock_price_with_date_available(self):
     stock_uri = "adidas-Aktie"
     quarterly = date.string_to_date("29.01.2019")
     closing_price, actual_date = db.get_closing_stock_price(
         quarterly, stock_uri, database=cst.TEST_DATABASE)
     self.assertEqual(204.90, float(closing_price))
Beispiel #14
0
    def test_write_stock_overview_history_to_db(self):
        overview_stock_history = [
            ["08.02.2019", "197,90"],
            ["07.02.2019", "197,90"],
            ["06.02.2019", "201,60"],
            ["05.02.2019", "202,70"],
            ["04.02.2019", "196,45"],
        ]
        stock_uri = "adidas-Aktie"
        self.assertTrue(
            db.write_stock_overview_history_to_db(overview_stock_history,
                                                  stock_uri,
                                                  cst.TEST_DATABASE))

        asserted_database_content = [
            [
                "adidas-Aktie",
                date.string_to_date("28.01.2019"), 203.10, 202.80
            ],
            [
                "adidas-Aktie",
                date.string_to_date("29.01.2019"), 203.20, 204.90
            ],
            [
                "adidas-Aktie",
                date.string_to_date("30.01.2019"), 204.10, 205.90
            ],
            [
                "adidas-Aktie",
                date.string_to_date("31.01.2019"), 206.90, 207.40
            ],
            [
                "adidas-Aktie",
                date.string_to_date("01.02.2019"), 202.30, 199.40
            ],
            ["adidas-Aktie",
             date.string_to_date("04.02.2019"), None, 196.45],
            ["adidas-Aktie",
             date.string_to_date("05.02.2019"), None, 202.70],
            ["adidas-Aktie",
             date.string_to_date("06.02.2019"), None, 201.60],
            ["adidas-Aktie",
             date.string_to_date("07.02.2019"), None, 197.90],
            ["adidas-Aktie",
             date.string_to_date("08.02.2019"), None, 197.90],
        ]
        validating_list = db.get_list(
            table=cst.TABLE_STOCKS_HISTORIES,
            columns=[
                cst.COLUMN_STOCK_URI,
                cst.COLUMN_DATE,
                cst.COLUMN_START_VALUE,
                cst.COLUMN_CLOSING_VALUE,
            ],
            condition=[cst.COLUMN_STOCK_URI, "adidas-Aktie"],
            database=cst.TEST_DATABASE,
        )
        converted_validating_list = [[
            item[0],
            item[1],
            float(item[2]) if item[2] is not None else None,
            float(item[3]) if item[3] is not None else None,
        ] for item in validating_list]
        self.assertEqual(asserted_database_content.sort(),
                         converted_validating_list.sort())