maximize cache usage
This commit is contained in:
+24
-20
@@ -42,6 +42,10 @@ def dependency_setup():
|
|||||||
|
|
||||||
print('dependencies ready')
|
print('dependencies ready')
|
||||||
|
|
||||||
|
def today():
|
||||||
|
now=datetime.utcnow()
|
||||||
|
return datetime(now.year,now.month,now.day)
|
||||||
|
|
||||||
# Astrology functions
|
# Astrology functions
|
||||||
|
|
||||||
def load_settings():
|
def load_settings():
|
||||||
@@ -63,7 +67,7 @@ def is_retrograde(speed):
|
|||||||
return speed<0
|
return speed<0
|
||||||
|
|
||||||
@cache
|
@cache
|
||||||
def get_positions_raw(date):
|
def get_positions_raw(date=today()):
|
||||||
import swisseph as swe
|
import swisseph as swe
|
||||||
julian_day = swe.julday(date.year, date.month, date.day)
|
julian_day = swe.julday(date.year, date.month, date.day)
|
||||||
planets = {
|
planets = {
|
||||||
@@ -97,7 +101,7 @@ def get_positions_raw(date):
|
|||||||
return positions
|
return positions
|
||||||
|
|
||||||
@cache
|
@cache
|
||||||
def get_positions(date):
|
def get_positions(date=today()):
|
||||||
positions={}
|
positions={}
|
||||||
|
|
||||||
for name, position_raw in get_positions_raw(date).items():
|
for name, position_raw in get_positions_raw(date).items():
|
||||||
@@ -129,7 +133,7 @@ def get_list_formatted(in_list,isare=True):
|
|||||||
return output
|
return output
|
||||||
|
|
||||||
@cache
|
@cache
|
||||||
def get_positions_formatted(date):
|
def get_positions_formatted(date=today()):
|
||||||
retrograde_planets=[]
|
retrograde_planets=[]
|
||||||
position_strings=[]
|
position_strings=[]
|
||||||
|
|
||||||
@@ -148,15 +152,14 @@ def get_positions_formatted(date):
|
|||||||
|
|
||||||
return positions_formatted
|
return positions_formatted
|
||||||
|
|
||||||
def get_transits():
|
@cache
|
||||||
seconds_in_1_day=86400
|
def get_transits(date=today(), maxdays=28):
|
||||||
now=datetime.utcnow()
|
positions_now=get_positions(date)
|
||||||
positions_now=get_positions(now)
|
|
||||||
transits={}
|
transits={}
|
||||||
days=1
|
days=1
|
||||||
|
|
||||||
while len(transits)<12 and days<29:
|
while len(transits)<12 and days<maxdays:
|
||||||
future_timestamp=now.timestamp()+(days*seconds_in_1_day)
|
future_timestamp=date.timestamp()+(days*seconds_in_1_day)
|
||||||
future_date=datetime.fromtimestamp(future_timestamp,timezone.utc)
|
future_date=datetime.fromtimestamp(future_timestamp,timezone.utc)
|
||||||
positions_future=get_positions(future_date)
|
positions_future=get_positions(future_date)
|
||||||
for name, position_future in positions_future.items():
|
for name, position_future in positions_future.items():
|
||||||
@@ -172,11 +175,12 @@ def get_transits():
|
|||||||
|
|
||||||
return transits
|
return transits
|
||||||
|
|
||||||
def get_transits_formatted():
|
@cache
|
||||||
|
def get_transits_formatted(date=today(), maxdays=28):
|
||||||
date_format='%b %d'
|
date_format='%b %d'
|
||||||
transits_formatted=''
|
transits_formatted=''
|
||||||
|
|
||||||
for name,transit in get_transits().items():
|
for name,transit in get_transits(date, maxdays).items():
|
||||||
if transit['zodiac']!=None:
|
if transit['zodiac']!=None:
|
||||||
transits_formatted+=name+' is entering '+transit['zodiac']+' on '+transit['date'].strftime(date_format)+'\n'
|
transits_formatted+=name+' is entering '+transit['zodiac']+' on '+transit['date'].strftime(date_format)+'\n'
|
||||||
if transit['retrograde']==True:
|
if transit['retrograde']==True:
|
||||||
@@ -187,7 +191,7 @@ def get_transits_formatted():
|
|||||||
return transits_formatted
|
return transits_formatted
|
||||||
|
|
||||||
@cache
|
@cache
|
||||||
def get_aspects(date, minor=False):
|
def get_aspects(date=today(), minor=False):
|
||||||
positions=get_positions_raw(date)
|
positions=get_positions_raw(date)
|
||||||
major_aspects={
|
major_aspects={
|
||||||
'conjuction':{'angle':0,'orb':10.0},
|
'conjuction':{'angle':0,'orb':10.0},
|
||||||
@@ -231,7 +235,7 @@ def get_aspects(date, minor=False):
|
|||||||
return aspects
|
return aspects
|
||||||
|
|
||||||
@cache
|
@cache
|
||||||
def get_aspects_formatted(date,minor=False):
|
def get_aspects_formatted(date=today(),minor=False):
|
||||||
aspects_formatted=''
|
aspects_formatted=''
|
||||||
|
|
||||||
for planet,aspects in get_aspects(date,minor).items():
|
for planet,aspects in get_aspects(date,minor).items():
|
||||||
@@ -340,7 +344,7 @@ def main():
|
|||||||
async def on_chat_message(data: eventsub.chat.MessageEvent):
|
async def on_chat_message(data: eventsub.chat.MessageEvent):
|
||||||
config=load_settings()
|
config=load_settings()
|
||||||
if data['message']['text']==config['positions']:
|
if data['message']['text']==config['positions']:
|
||||||
for line in get_positions_formatted(datetime.now()).splitlines(False):
|
for line in get_positions_formatted().splitlines(False):
|
||||||
await client.channel.chat.send_message(line,data['message_id'])
|
await client.channel.chat.send_message(line,data['message_id'])
|
||||||
return
|
return
|
||||||
if data['message']['text']==config['transits']:
|
if data['message']['text']==config['transits']:
|
||||||
@@ -348,11 +352,11 @@ def main():
|
|||||||
await client.channel.chat.send_message(line,data['message_id'])
|
await client.channel.chat.send_message(line,data['message_id'])
|
||||||
return
|
return
|
||||||
if data['message']['text']==config['major_aspects']:
|
if data['message']['text']==config['major_aspects']:
|
||||||
for line in get_aspects_formatted(datetime.now()).splitlines(False):
|
for line in get_aspects_formatted().splitlines(False):
|
||||||
await client.channel.chat.send_message(line,data['message_id'])
|
await client.channel.chat.send_message(line,data['message_id'])
|
||||||
return
|
return
|
||||||
if data['message']['text']==config['minor_aspects']:
|
if data['message']['text']==config['minor_aspects']:
|
||||||
for line in get_aspects_formatted(datetime.now(),True).splitlines(False):
|
for line in get_aspects_formatted(minor=True).splitlines(False):
|
||||||
await client.channel.chat.send_message(line,data['message_id'])
|
await client.channel.chat.send_message(line,data['message_id'])
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -448,8 +452,8 @@ if __name__ == '__main__':
|
|||||||
def script_path():
|
def script_path():
|
||||||
return path.dirname(__file__)+'/'
|
return path.dirname(__file__)+'/'
|
||||||
dependency_setup()
|
dependency_setup()
|
||||||
#print(get_positions_formatted(datetime(2025,7,21)))
|
print(get_positions_formatted())
|
||||||
#print(get_transits_formatted())
|
print(get_transits_formatted())
|
||||||
#main()
|
#main()
|
||||||
print(get_aspects_formatted(datetime(2025,7,21)))
|
print(get_aspects_formatted())
|
||||||
print(get_aspects_formatted(datetime(2025,7,21),True))
|
print(get_aspects_formatted(minor=True))
|
||||||
Reference in New Issue
Block a user