question about making an App for Android

Cousin Stanley cousinstanley at gmail.com
Tue Oct 15 20:02:58 EDT 2019


Chris Angelico wrote:

> Or.... maybe it's really simple, because there's an HTTP API 
>that > gives you the information. 
>
> There's an API for everything these days. 
> 
> A quick web search showed up this:
> 
>   https://sunrise-sunset.org/api
> ....

  There is also a useful python package
  called  sunset  which I fouund a reference to
  on stackoverflow ....

    https://stackoverflow.com/questions/38986527/sunrise-and-sunset-time-in-python/38986561

  # pip3 install sunset

  # pip 3 show sunset
  os pip3 show suntime
  Name: suntime
  Version: 1.2.5
  Summary: Simple sunset and sunrise time calculation python library
  Home-page: https://github.com/SatAgro/suntime
  Author: Krzysztof Stopa
  Author-email: None
  License: LGPLv3
  Location: /usr/local/lib/python3.7/dist-packages
  Requires: python-dateutil
  Required-by: 

  If latidude and longitude are known
  sunrise and sunset times are available .... 

$ cat daylight_phoenix.py

#!/usr/bin/env python3

'''
    NewsGroup .... comp.lang.python 
    Subject ...... question about maiking an App for Android
    Date ......... 2019-10-10
    Post_By ...... pyotr filipivich

    Code_By ...... Stanley C. Kitching
    Code_Date .... 2019-10-10 
'''

import time
import datetime as dt

from suntime import Sun , SunTimeException

# Phoenix, Arizona

latitude  = 33.4484     # ° N

longitude = 112.0740    # ° W

sun = Sun( latitude , longitude )

# Get today's sunrise and sunset in UTC

sunrise = sun.get_sunrise_time()

sunset  = sun.get_sunset_time()

sse_sunrise = sunrise.timestamp()  # sunrise seconds since epoch

sse_sunset  = sunset.timestamp()   # sunset  seconds since epoch

d_sse       = sse_sunset - sse_sunrise  # seconds of daylight

print( '\n  Today in Phoenix ....' )

print( '\n     sunrise : ' , sunrise , '  ' , sse_sunrise )
print( '\n     sunset  : ' , sunset  , '  ' , sse_sunset  )
print( '\n    daylight :  {} seconds '.format( d_sse ) )

# -----------------------------------------------------------------

 
-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona




More information about the Python-list mailing list