Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New to programming -- Keep getting AttributeError #61

Open
diordaemon opened this issue Mar 31, 2023 · 2 comments
Open

New to programming -- Keep getting AttributeError #61

diordaemon opened this issue Mar 31, 2023 · 2 comments

Comments

@diordaemon
Copy link

I'm on Windows 10. Running python 3.7 on a conda virtual env. Using VScode.

I have tried to install swisseph and pyswisseph in every way possible to try and get it to work. I finally got swisseph working and recognized as a module, and I'm using chatgpt to help me write code and learn how to integrate the ephermis into the gpt api. We're going through the steps and it gave me the example code below to use to connect with postman/flask and run the calculate_planet_position function.

The problem is that when I run it, the attribute swe.MERCURY and swe.FLG_SPEED and swe.FLG_SWIEPH and the other attributes are just not being recognized for some reason by my terminal.

I keep getthing the error: AttributeError: module 'swisseph' has no attribute 'FLG_SWIEPH

I dont know what I'm doing wrong. Was hoping to get some help with this.

`
from flask import Flask, request
import swisseph as swe

app = Flask(__name__)

@app.route('/planet_position', methods=['GET'])
def planet_position():
    # Get the parameters from the request
    date = float(request.args.get('date'))
    longitude = float(request.args.get('longitude'))
    latitude = float(request.args.get('latitude'))


    # Call the calculate_planet_position function to get the planet's position
    planet_longitude, planet_latitude = calculate_planet_position(date, longitude, latitude)

    # Return the planet's position as a JSON response
    return {
        'planet_longitude': planet_longitude,
        'planet_latitude': planet_latitude
    }

def calculate_planet_position(date, longitude, latitude):
    """
    Calculates the position of Mercury at a given date, longitude, and latitude.

    Args:
        date (float): The date and time in Julian days UTC.
        longitude (float): The longitude of the observer in degrees.
        latitude (float): The latitude of the observer in degrees.

    Returns:
        tuple: The longitude and latitude of Mercury in degrees.
    """
    # Set up the parameters for the calculation
    planet = 1  # Use the integer planet number for Mercury
    flags = swe.FLG_SWIEPH | swe.FLG_SPEED
    position_format = swe.FLG_EQUATORIAL | swe.FLG_SPEED | swe.FLG_TRUEPOS

    # Set the observer location
    observer_location = [longitude, latitude, 0]

    # Calculate the planet's position
    planet_position = swe.calc_ut(date, planet, flags)
    planet_longitude, planet_latitude, _ = swe.calc_ut(planet_position[0], planet, position_format)

    # Convert the planet's position to the observer's location
    swe.set_topo(observer_location[0], observer_location[1], observer_location[2])
    swe.set_sid_mode(swe.SIDM_LAHIRI)
    planet_longitude, planet_latitude, _ = swe.get_topo(planet_longitude)

if __name__ == '__main__':
    app.run()

`

@ShadowJonathan
Copy link
Collaborator

Could you run pip list? To confirm the pyswisseph version you have installed.

@mnsarma
Copy link

mnsarma commented Jun 15, 2023

you have to add path first, to use any functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants