1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Flatlib use current date and time

Discussão em 'Python' iniciado por Stack, Setembro 8, 2025.

  1. Stack

    Stack Membro Participativo

    Can someone help with me this?

    I am using Flatlib to compute planet positions, but the code for entering the date and time for computation is fixed, so you have to update it each time.

    Is there a way to using datetime.now() [or another way] to complete the fields in the Datetime() automatically? I can't get the code in the date = Datetime() to accept any form of datetime code.

    I looking to get Datetime() to accept month/day/year and hour:minute:second format eg (08/24/2018, 21:17:00)

    With the below code i get the following error:

    C:\Users\famil>C:\Users\famil\Desktop\flatlib_working_degree.py ('{0.month}/{0.day}/{0.year}', '21:15:41') Traceback (most recent call last): File "C:\Users\famil\Desktop\flatlib_working_degree.py", line 13, in date = Datetime(x) File "C:\Users\famil\AppData\Local\Programs\Python\Python37-32\lib\site-packages\flatlib\datetime.py", line 177, in init self.date = Date(date, calendar) File "C:\Users\famil\AppData\Local\Programs\Python\Python37-32\lib\site-packages\flatlib\datetime.py", line 76, in init self.jdn = int(value) TypeError: int() argument must be a string, a bytes-like object or a number, not 'tuple'

    from flatlib.datetime import Datetime
    from flatlib.geopos import GeoPos
    from flatlib.chart import Chart
    from flatlib import const
    import datetime

    # set date and time to now

    now = datetime.datetime.now()
    x = '{0.month}/{0.day}/{0.year}, {0.hour}:{0.minute}:{0.second}'.format(now)
    print(x)
    date = Datetime(x)
    pos = GeoPos('53n15', '2e31')

    chart = Chart(date, pos, hsys=const.HOUSES_PLACIDUS, IDs=const.LIST_OBJECTS)

    # calculate body and degree value
    asc = chart.get(const.ASC)
    print(asc, asc.lon)
    sun = chart.get(const.SUN)
    print(sun, sun.lon, sun.movement())
    moon = chart.get(const.MOON)

    Continue reading...

Compartilhe esta Página