Esempio n. 1
0
def is_holiday(date, country_code):
    # Requirement: holidays python library (https://pypi.org/project/holidays/)
    # Install: pip install holidays
    try:
        import holidays
        isCountryFound = False
        for country in holidays.list_supported_countries():
            if country_code == country:
                print(('Found country code "{}"'.format(country_code)))
                country_holidays = holidays.CountryHoliday(country_code)
                isCountryFound = True
                break

        if (isCountryFound == False):
            print((
                'Error: given country code "{}" is not found in supported country codes'
                .format(country_code)))
            print(holidays.list_supported_countries())
            return False

        return date.date() in country_holidays

    except ImportError as err:
        print('*** Could not import "holidays" Python module ***')
        print(
            'Please install "holidays", or Holidays are not taken into account.'
        )
        print('To install, type pip install holidays')
        return False
Esempio n. 2
0
def holiday_country(country, date):

    # the two anomalies in code in holidays w.r.t oxford country codes
    # case for morocco and bulgaria
    if country == "MAR":
        country == "MOR"
    if country == "BGR":
        country == "BLG"

    if country in holidays.list_supported_countries():
        func = getattr(holidays, country)
        if date in func():
            return 2  # return holiday (priority over weekend)

    return int(parse(date).weekday() in WEEKENDS[country])
Esempio n. 3
0
def valid_country(value: Any) -> str:
    """Validate that the given country is supported."""
    value = cv.string(value)
    all_supported_countries = holidays.list_supported_countries()

    try:
        raw_value = value.encode("utf-8")
    except UnicodeError as err:
        raise vol.Invalid(
            "The country name or the abbreviation must be a valid UTF-8 string."
        ) from err
    if not raw_value:
        raise vol.Invalid("Country name or the abbreviation must not be empty.")
    if value not in all_supported_countries:
        raise vol.Invalid("Country is not supported.")
    return value
 def test_list_supported_countries(self):
     self.assertIn("AR", holidays.list_supported_countries())
     self.assertIn("ZA", holidays.list_supported_countries())
provinces = holidays.IN.PROVINCES
dataset = []
for province in provinces:
    dataset.append({
        "Province":
        province,
        "Holiday_Days":
        len(holidays.IN(years=2020, observed=False, prov=province))
    })
india = pandas.DataFrame(dataset)
india = india.sort_values(by="Holiday_Days", ascending=False)
india[0:10].plot(kind="bar", x="Province", y="Holiday_Days")
plt.show()

countries = []
for country in holidays.list_supported_countries():
    if len(country) > 3:
        countries.append(country)
    else:
        pass
print(countries)
print("\n")
datasett = []
for country in countries:
    try:
        datasett.append({
            "Country":
            country,
            "Holiday_Days":
            len(holidays.CountryHoliday(country, years=2020, observed=False))
        })