def setUp(self): self.holidays = holidays.ES(observed=False) self.holidays_observed = holidays.ES() self.prov_holidays = { prov: holidays.ES(observed=False, prov=prov) for prov in holidays.ES.PROVINCES }
def add_holidays(data): """Add the holidays of 2018 in Barcelona as a column of dataframe data from function get_data(). Parameters ---------- data : pandas.DataFrame data from function get_data() Returns ------- data : with new holiday column """ holidays = pd.DatetimeIndex([*vacations.ES(prov='CAT', years=2018)]) origIndex = data.index data.index = origIndex.floor('D') data = data.join(pd.Series(1, index=holidays, name='holiday')) data['holiday'].fillna(0, inplace=True) data.index = origIndex # check if 0: print(any(data['holiday'] == 1)) print(data.iloc[690000, :]) # 2018-12-06 is a holiday in Bcn data.loc[690000, 'holiday'] return data
def _get_public_days(week): # Holidays not available (Catalunya). public_days = holidays.ES(years=week.year, prov="CAT") week_pd = {} [ week_pd.update({k: v}) for k, v in public_days.items() if _get_week(k) == week ] return week_pd
def judge_local_holiday(self, df): country = df['geoNetwork_country'] date = df['visitId'].apply(lambda x: x.date()) judge_holiday = \ np.where(country.isin( ['United States','India','Canada','Germany', 'Japan','France','Mexico','Australia', 'Spain','Netherlands','Italy','Ireland', 'Sweden','Argentina','Colombia','Belgium', 'Switzerland','Czechia','Colombia','Belgium', 'New Zealand','South Africa','South Africa']),\ np.where((country=='United States')& (date.isin(holidays.US())),1, np.where((country=='India')& (date.isin(holidays.India())),1, np.where((country=='Canada')& (date.isin(holidays.CA())),1, np.where((country=='Germany')& (date.isin(holidays.DE())),1,\ np.where((country=='Japan')& (date.isin(holidays.JP())),1, np.where((country=='France')& (date.isin(holidays.FRA())),1, np.where((country=='Mexico')& (date.isin(holidays.MX())),1, np.where((country=='Australia')& (date.isin(holidays.AU())),1,\ np.where((country=='Spain')& (date.isin(holidays.ES())),1, np.where((country=='Netherlands')& (date.isin(holidays.NL())),1, np.where((country=='Italy')& (date.isin(holidays.IT())),1, np.where((country=='Ireland')& (date.isin(holidays.IE())),1,\ np.where((country=='Sweden')& (date.isin(holidays.SE())),1, np.where((country=='Argentina')& (date.isin(holidays.AR())),1, np.where((country=='Colombia')& (date.isin(holidays.CO())),1, np.where((country=='Belgium')& (date.isin(holidays.BE())),1,\ np.where((country=='Switzerland')& (date.isin(holidays.CH())),1, np.where((country=='Czechia')& (date.isin(holidays.CZ())),1, np.where((country=='Denmark')& (date.isin(holidays.DK())),1, np.where((country=='Austria')& (date.isin(holidays.AT())),1,\ np.where((country=='Hungary')& (date.isin(holidays.HU())),1, np.where((country=='Portugal')& (date.isin(holidays.PT())),1, np.where((country=='Norway')& (date.isin(holidays.NO())),1, np.where((country=='Portugal')& (date.isin(holidays.PT())),1,\ np.where((country=='New Zealand')& (date.isin(holidays.NZ())),1, np.where((country=='South Africa')& (date.isin(holidays.ZA())),1, np.where((country=='South Africa')& (date.isin(holidays.ZA())),1,\ 0))))))))))))))))))))))))))),np.nan).astype(int) return judge_holiday
def anadirdias(): if request.method == "POST": daystoadd = request.values.get("AnForm") session["daystoadd"] = daystoadd omitN = request.form.get("cnt") comunidades = request.form.get("comunidades") dateVal = request.form.get("dateAn") if str(daystoadd) == "": return redirect(url_for("anadirdias")) else: if omitN: # holiday database days_to_skipPV = holidays.ES(prov='PV', years=2020) days_to_skipAND = holidays.ES(prov='AN', years=2020) days_to_skipARG = holidays.ES(prov='AR', years=2020) days_to_skipAST = holidays.ES(prov='AS', years=2020) days_to_skipCN = holidays.ES(prov='CB', years=2020) days_to_skipCM = holidays.ES(prov='CM', years=2020) days_to_skipCL = holidays.ES(prov='CL', years=2020) days_to_skipCAT = holidays.ES(prov='CT', years=2020) days_to_skipVA = holidays.ES(prov='CVA', years=2020) days_to_skipEXT = holidays.ES(prov='EX', years=2020) days_to_skipGA = holidays.ES(prov='GA', years=2020) days_to_skipIBA = holidays.ES(prov='IB', years=2020) days_to_skipICA = holidays.ES(prov='CN', years=2020) days_to_skipMAD = holidays.ES(prov='MD', years=2020) days_to_skipMUR = holidays.ES(prov='MC', years=2020) days_to_skipNAV = holidays.ES(prov='NC', years=2020) days_to_skipRIO = holidays.ES(prov='RI', years=2020) # declaración de variables weekendsSkip = 0 skipped = 0 if dateVal == "": start = date.today() else: start = datetime.strptime(dateVal, "%Y-%m-%d").date() xres = start # if para comunidades #andalusia if comunidades == 'and': # checkeo de fines for days in range(int(daystoadd) + 1): xres += timedelta(days=1) weekday = xres.weekday() if weekday >= 5: weekendsSkip += 1 finalWeek = weekendsSkip # checkeo de fiestas for days_add in range(int(daystoadd) + 1): if start + timedelta(days=days_add) in days_to_skipAND: skipped += 1 resultAn = start + timedelta(days=int(daystoadd)) + timedelta(days=skipped) + timedelta(days=finalWeek) if resultAn.weekday() >= 5: resultAn += timedelta(days=2) weekDayResult = resultAn.strftime('%a, %d/%m/%Y') session["an_result"] = weekDayResult return redirect(url_for('an_result')) if comunidades == 'ar': # checkeo de fines for days in range(int(daystoadd) + 1): xres += timedelta(days=1) weekday = xres.weekday() if weekday >= 5: weekendsSkip += 1 finalWeek = weekendsSkip # checkeo de fiestas for days_add in range(int(daystoadd) + 1): if start + timedelta(days=days_add) in days_to_skipARG: skipped += 1 resultAn = start + timedelta(days=int(daystoadd)) + timedelta(days=skipped) + timedelta(days=finalWeek) if resultAn.weekday() >= 5: resultAn += timedelta(days=2) weekDayResult = resultAn.strftime('%a, %d/%m/%Y') session["an_result"] = weekDayResult return redirect(url_for('an_result')) if comunidades == 'as': # checkeo de fines for days in range(int(daystoadd) + 1): xres += timedelta(days=1) weekday = xres.weekday() if weekday >= 5: weekendsSkip += 1 finalWeek = weekendsSkip # checkeo de fiestas for days_add in range(int(daystoadd) + 1): if start + timedelta(days=days_add) in days_to_skipAST: skipped += 1 resultAn = start + timedelta(days=int(daystoadd)) + timedelta(days=skipped) + timedelta(days=finalWeek) if resultAn.weekday() >= 5: resultAn += timedelta(days=2) weekDayResult = resultAn.strftime('%a, %d/%m/%Y') session["an_result"] = weekDayResult return redirect(url_for('an_result')) if comunidades == 'can': # checkeo de fines for days in range(int(daystoadd) + 1): xres += timedelta(days=1) weekday = xres.weekday() if weekday >= 5: weekendsSkip += 1 finalWeek = weekendsSkip # checkeo de fiestas for days_add in range(int(daystoadd) + 1): if start + timedelta(days=days_add) in days_to_skipCN: skipped += 1 resultAn = start + timedelta(days=int(daystoadd)) + timedelta(days=skipped) + timedelta(days=finalWeek) if resultAn.weekday() >= 5: resultAn += timedelta(days=2) weekDayResult = resultAn.strftime('%a, %d/%m/%Y') session["an_result"] = weekDayResult return redirect(url_for('an_result')) if comunidades == 'cm': # checkeo de fines for days in range(int(daystoadd) + 1): xres += timedelta(days=1) weekday = xres.weekday() if weekday >= 5: weekendsSkip += 1 finalWeek = weekendsSkip # checkeo de fiestas for days_add in range(int(daystoadd) + 1): if start + timedelta(days=days_add) in days_to_skipCM: skipped += 1 resultAn = start + timedelta(days=int(daystoadd)) + timedelta(days=skipped) + timedelta(days=finalWeek) if resultAn.weekday() >= 5: resultAn += timedelta(days=2) weekDayResult = resultAn.strftime('%a, %d/%m/%Y') session["an_result"] = weekDayResult return redirect(url_for('an_result')) if comunidades == 'cl': # checkeo de fines for days in range(int(daystoadd) + 1): xres += timedelta(days=1) weekday = xres.weekday() if weekday >= 5: weekendsSkip += 1 finalWeek = weekendsSkip # checkeo de fiestas for days_add in range(int(daystoadd) + 1): if start + timedelta(days=days_add) in days_to_skipCL: skipped += 1 resultAn = start + timedelta(days=int(daystoadd)) + timedelta(days=skipped) + timedelta(days=finalWeek) if resultAn.weekday() >= 5: resultAn += timedelta(days=2) weekDayResult = resultAn.strftime('%a, %d/%m/%Y') session["an_result"] = weekDayResult return redirect(url_for('an_result')) if comunidades == 'cat': # checkeo de fines for days in range(int(daystoadd) + 1): xres += timedelta(days=1) weekday = xres.weekday() if weekday >= 5: weekendsSkip += 1 finalWeek = weekendsSkip # checkeo de fiestas for days_add in range(int(daystoadd) + 1): if start + timedelta(days=days_add) in days_to_skipCAT: skipped += 1 resultAn = start + timedelta(days=int(daystoadd)) + timedelta(days=skipped) + timedelta(days=finalWeek) if resultAn.weekday() >= 5: resultAn += timedelta(days=2) weekDayResult = resultAn.strftime('%a, %d/%m/%Y') session["an_result"] = weekDayResult return redirect(url_for('an_result')) if comunidades == 'va': # checkeo de fines for days in range(int(daystoadd) + 1): xres += timedelta(days=1) weekday = xres.weekday() if weekday >= 5: weekendsSkip += 1 finalWeek = weekendsSkip # checkeo de fiestas for days_add in range(int(daystoadd) + 1): if start + timedelta(days=days_add) in days_to_skipVA: skipped += 1 resultAn = start + timedelta(days=int(daystoadd)) + timedelta(days=skipped) + timedelta(days=finalWeek) if resultAn.weekday() >= 5: resultAn += timedelta(days=2) weekDayResult = resultAn.strftime('%a, %d/%m/%Y') session["an_result"] = weekDayResult return redirect(url_for('an_result')) if comunidades == 'ex': # checkeo de fines for days in range(int(daystoadd) + 1): xres += timedelta(days=1) weekday = xres.weekday() if weekday >= 5: weekendsSkip += 1 finalWeek = weekendsSkip # checkeo de fiestas for days_add in range(int(daystoadd) + 1): if start + timedelta(days=days_add) in days_to_skipEXT: skipped += 1 resultAn = start + timedelta(days=int(daystoadd)) + timedelta(days=skipped) + timedelta(days=finalWeek) if resultAn.weekday() >= 5: resultAn += timedelta(days=2) weekDayResult = resultAn.strftime('%a, %d/%m/%Y') session["an_result"] = weekDayResult return redirect(url_for('an_result')) if comunidades == 'ga': # checkeo de fines for days in range(int(daystoadd) + 1): xres += timedelta(days=1) weekday = xres.weekday() if weekday >= 5: weekendsSkip += 1 finalWeek = weekendsSkip # checkeo de fiestas for days_add in range(int(daystoadd) + 1): if start + timedelta(days=days_add) in days_to_skipGA: skipped += 1 resultAn = start + timedelta(days=int(daystoadd)) + timedelta(days=skipped) + timedelta(days=finalWeek) if resultAn.weekday() >= 5: resultAn += timedelta(days=2) weekDayResult = resultAn.strftime('%a, %d/%m/%Y') session["an_result"] = weekDayResult return redirect(url_for('an_result')) if comunidades == 'ba': # checkeo de fines for days in range(int(daystoadd) + 1): xres += timedelta(days=1) weekday = xres.weekday() if weekday >= 5: weekendsSkip += 1 finalWeek = weekendsSkip # checkeo de fiestas for days_add in range(int(daystoadd) + 1): if start + timedelta(days=days_add) in days_to_skipIBA: skipped += 1 resultAn = start + timedelta(days=int(daystoadd)) + timedelta(days=skipped) + timedelta(days=finalWeek) if resultAn.weekday() >= 5: resultAn += timedelta(days=2) weekDayResult = resultAn.strftime('%a, %d/%m/%Y') session["an_result"] = weekDayResult return redirect(url_for('an_result')) if comunidades == 'canarias': # checkeo de fines for days in range(int(daystoadd) + 1): xres += timedelta(days=1) weekday = xres.weekday() if weekday >= 5: weekendsSkip += 1 finalWeek = weekendsSkip # checkeo de fiestas for days_add in range(int(daystoadd) + 1): if start + timedelta(days=days_add) in days_to_skipICA: skipped += 1 resultAn = start + timedelta(days=int(daystoadd)) + timedelta(days=skipped) + timedelta(days=finalWeek) if resultAn.weekday() >= 5: resultAn += timedelta(days=2) weekDayResult = resultAn.strftime('%a, %d/%m/%Y') session["an_result"] = weekDayResult return redirect(url_for('an_result')) if comunidades == 'rio': # checkeo de fines for days in range(int(daystoadd) + 1): xres += timedelta(days=1) weekday = xres.weekday() if weekday >= 5: weekendsSkip += 1 finalWeek = weekendsSkip # checkeo de fiestas for days_add in range(int(daystoadd) + 1): if start + timedelta(days=days_add) in days_to_skipRIO: skipped += 1 resultAn = start + timedelta(days=int(daystoadd)) + timedelta(days=skipped) + timedelta(days=finalWeek) if resultAn.weekday() >= 5: resultAn += timedelta(days=2) weekDayResult = resultAn.strftime('%a, %d/%m/%Y') session["an_result"] = weekDayResult return redirect(url_for('an_result')) if comunidades == 'mad': # checkeo de fines for days in range(int(daystoadd) + 1): xres += timedelta(days=1) weekday = xres.weekday() if weekday >= 5: weekendsSkip += 1 finalWeek = weekendsSkip # checkeo de fiestas for days_add in range(int(daystoadd) + 1): if start + timedelta(days=days_add) in days_to_skipMAD: skipped += 1 resultAn = start + timedelta(days=int(daystoadd)) + timedelta(days=skipped) + timedelta(days=finalWeek) if resultAn.weekday() >= 5: resultAn += timedelta(days=2) weekDayResult = resultAn.strftime('%a, %d/%m/%Y') session["an_result"] = weekDayResult return redirect(url_for('an_result')) if comunidades == 'mur': # checkeo de fines for days in range(int(daystoadd) + 1): xres += timedelta(days=1) weekday = xres.weekday() if weekday >= 5: weekendsSkip += 1 finalWeek = weekendsSkip # checkeo de fiestas for days_add in range(int(daystoadd) + 1): if start + timedelta(days=days_add) in days_to_skipMUR: skipped += 1 resultAn = start + timedelta(days=int(daystoadd)) + timedelta(days=skipped) + timedelta(days=finalWeek) if resultAn.weekday() >= 5: resultAn += timedelta(days=2) weekDayResult = resultAn.strftime('%a, %d/%m/%Y') session["an_result"] = weekDayResult return redirect(url_for('an_result')) if comunidades == 'nav': # checkeo de fines for days in range(int(daystoadd) + 1): xres += timedelta(days=1) weekday = xres.weekday() if weekday >= 5: weekendsSkip += 1 finalWeek = weekendsSkip # checkeo de fiestas for days_add in range(int(daystoadd) + 1): if start + timedelta(days=days_add) in days_to_skipNAV: skipped += 1 resultAn = start + timedelta(days=int(daystoadd)) + timedelta(days=skipped) + timedelta(days=finalWeek) if resultAn.weekday() >= 5: resultAn += timedelta(days=2) weekDayResult = resultAn.strftime('%a, %d/%m/%Y') session["an_result"] = weekDayResult return redirect(url_for('an_result')) if comunidades == 'euskadi': # checkeo de fines for days in range(int(daystoadd) + 1): xres += timedelta(days=1) weekday = xres.weekday() if weekday >= 5: weekendsSkip += 1 finalWeek = weekendsSkip # checkeo de fiestas for days_add in range(int(daystoadd) + 1): if start + timedelta(days=days_add) in days_to_skipPV: skipped += 1 resultAn = start + timedelta(days=int(daystoadd)) + timedelta(days=skipped) + timedelta(days=finalWeek) if resultAn.weekday() >= 5: resultAn += timedelta(days=2) weekDayResult = resultAn.strftime('%a, %d/%m/%Y') session["an_result"] = weekDayResult return redirect(url_for('an_result')) else: daystoAdd = int(daystoadd) date_today = date.today() result = date_today + timedelta(days=daystoAdd) add_result = result.strftime('%a, %d/%m/%Y') session["an_result"] = add_result return redirect(url_for("an_result")) else: return render_template("anadirDias.html")
return country_last country_holidays = { "CA": holidays.CA(), "CO": holidays.CO(), "MX": holidays.MX(), "US": holidays.US(), "NZ": holidays.NZ(), "AU": holidays.AU(), "DE": holidays.DE(), "AT": holidays.AT(), "DK": holidays.DK(), "UK": holidays.UK(), "IE": holidays.IE(), "ES": holidays.ES(), "CZ": holidays.CZ(), "SK": holidays.SK(), "PL": holidays.PL(), "PT": holidays.PT(), "NL": holidays.NL(), "NO": holidays.NO(), "IT": holidays.IT(), "SE": holidays.SE(), "JP": holidays.JP(), "BE": holidays.BE(), "ZA": holidays.ZA(), "SI": holidays.SI(), "FI": holidays.FI(), "CH": holidays.CH() }
with st.beta_expander('Holidays'): #st.markdown("""[Available countries list](https://github.com/dr-prodigy/python-holidays) """) countries = ['Country name','Italy','Spain','United States','France','Germany','Ukraine'] with st.beta_container(): years=[2021] selected_country = st.selectbox(label="Select country",options=countries) if selected_country == 'Italy': for date, name in sorted(holidays.IT(years=years).items()): st.write(date,name) if selected_country == 'Spain': for date, name in sorted(holidays.ES(years=years).items()): st.write(date,name) if selected_country == 'United States': for date, name in sorted(holidays.US(years=years).items()): st.write(date,name) if selected_country == 'France': for date, name in sorted(holidays.FR(years=years).items()): st.write(date,name) if selected_country == 'Germany': for date, name in sorted(holidays.DE(years=years).items()):