hello everbody,
I'm writing a python3 script which should check daily for the day of easter and if the difference is 5 days it should trigger another script (via an os-command). So far I tested the script with an static year (I used 2022) but now I want to be more dynamic by adding a datetime.now().year but this breaks the script:
I'm writing a python3 script which should check daily for the day of easter and if the difference is 5 days it should trigger another script (via an os-command). So far I tested the script with an static year (I used 2022) but now I want to be more dynamic by adding a datetime.now().year but this breaks the script:
!/usr/bin/env python3
#Imports
from datetime import datetime
from datetime import date
import datetime
import sys
#Calculation of easter date
def calc_easter(year):
"""returns the date of Easter Sunday of the given yyyy year"""
y = int(year)
# golden year - 1
g = y % 19
# offset
e = 0
# century
c = y/100
# h is (23 - Epact) mod 30
h = (c-c/4-(8*c+13)/25+19*g+15)%30
# number of days from March 21 to Paschal Full Moon
i = h-(h/28)*(1-(h/28)*(29/(h+1))*((21-g)/11))
# weekday for Paschal Full Moon (0=Sunday)
j = (y+y/4+i+2-c+c/4)%7
# number of days from March 21 to Sunday on or before Paschal Full Moon
# p can be from -6 to 28
p = i-j+e
d = int(1+(p+27+(p+6)/40)%31)
m = int(3+(p+26)/30)
return datetime.date(y,m,d)
#Calculation of difference
if __name__ == '__main__':
date1 = calc_easter(datetime.now().year)
date2 = date.today()
def numOfDays(date1, date2):
return (date2-date1).days
delta = int(numOfDays(date1, date2))
#Send mails
if delta == 5:
print ('Success')
elif delta == 10:
print ('No Success')
else:
print ('Not in range')
#End
sys.exit()Without any commenting on the Imports I get this error message:Traceback (most recent call last):
File "/home/pi/system/easter/beaster.py", line 34, in <module>
date1 = calc_easter(datetime.now().year)
AttributeError: module 'datetime' has no attribute 'now'But when I uncomment Import datetime I get this error message:Traceback (most recent call last):
File "/home/pi/system/easter/beaster.py", line 34, in <module>
date1 = calc_easter(datetime.now().year)
File "/home/pi/system/easter/beaster.py", line 30, in calc_easter
return datetime.date(y,m,d)
TypeError: descriptor 'date' for 'datetime.datetime' objects doesn't apply to a 'int' objectDoes anyone know how to help?
