Ejemplo n.º 1
0
def geoPrefs(xPrefs):

    info = " ** Geolocation details."

    cLocation = ""
    if 'location' in xPrefs:
        cLocation = xPrefs['location'].encode('utf-8')

    rv = {}
    if 'geo' not in xPrefs:
        xPrefs['geo'] = 'ip'

    if xPrefs['geo'] == 'fix':
            rv['latitude'] = xPrefs['latitude']
            rv['longitude'] = xPrefs['longitude']
            info += "  GeoCoordinates fixed!"

    if (xPrefs['geo']  == "-ip") or (xPrefs['geo']  == "ip"):
        rv = ipApi()

        # testing purpose only
        #print ("ipApi " + str(rv))
        #rv['location'] = ""
        #rv = {}

        if (('location' in rv) == False) or (rv['location'] == ""):
            #logInfo("  *** piGeoDetails (ip) failed, try (gmaps) *** \n", '31') # red
            logSys("  *** piGeoDetails (ip) failed, try (gmaps) *** \n", '31') # red
            xPrefs['geo'] = "-gmaps"


    if (xPrefs['geo'] == "-gmaps") or (xPrefs['geo'] == "gmaps"):
        rv = gMapsApi(cLocation)
        logSys(" geo gmaps status: " + str(rv['status']))

        if rv['status'] != 200:
            return rv

    rvS =  sunrise_sunset.getSunrise_Sunset(rv['latitude'], rv['longitude']) 

    rv['sunset'] = rvS['sunset']
    rv['sunrise'] = rvS['sunrise']
    rv['status'] = rvS['status']

    #print(" ***&&&  GeoDetails: " + str(rv))
    return rv
Ejemplo n.º 2
0
def suntime():
#---------------------------------
#  support Sunrise/Sunset with time values
#  time is calculated for actual day!

    if ('latitude' in xP.prefs) and ('longitude' in xP.prefs):

        rvS = sunrise_sunset.getSunrise_Sunset(xP.prefs['latitude'], xP.prefs['longitude'])
        xP.prefs['sunrise'] = rvS['sunrise']
        xP.prefs['sunset'] = rvS['sunset']

        logSys("&&  check suntime   sunrise:  " + str(xP.prefs['sunrise']))
        logSys("&&  check suntime   sunset:  " + str(xP.prefs['sunset']))

        prefsSaveJSON(None, None)

    else:
         pass