#!/usr/bin/python3

import cv2
import numpy as np
import requests
import time as tm

ra = 5.0
de = 5.0
raplus=0.02
deplus=0.02

url='https://skyserver.sdss.org/dr15/SkyServerWS/ImgCutout/getjpeg?ra={:.4f}1&dec={:.4f}&scale=2&width=256&height=256'
while True:
    urls=url.format(ra,de)
    req=requests.get(urls,stream=True).raw
    img=np.asarray(bytearray(req.read()),dtype="uint8")
    img=cv2.imdecode(img,cv2.IMREAD_COLOR)
    cv2.imwrite("./images/astimg.jpg",img)
    ra += raplus
#    print(urls)
    if ra > 65.0:
        raplus = -0.02
        ra = 65.0
        de += deplus
    if ra < -60.00:
        raplus = 0.02
        ra = -60.00
        de += deplus
    if de > 200.00:
        deplus = -0.02
        de = 200.0
    if de < -0.00:
        deplus = 0.02
        de = 0.00
        tm.sleep(15)
