Exemplo n.º 1
0
def nasaGet():
    '''
    Need to have your api key in the environment variables like so
        NASA_API_KEY : someRandomStringOfCharsAndNumbers
    Gets the date and tries to get the image
    :return: json with file information
    '''

    #Gets the current date
    date = datetime.datetime.now()
    year = date.year
    month = date.month
    day = date.day
    #Gets it in string format
    date = str(year)+"-"+str(month)+"-"+str(day)
    try:
        image = apod.apod(date)
        return jsonify(
            {
                'attachments': [
                {
                    'image_url': image.url,
                    'title' : image.title,
                    'text' : image.explanation
                }
                ]
            }
        )

    except:
        return "Failed to get image"
Exemplo n.º 2
0
def GetImageAst(date, image_name):
    pic = apod.apod('{y}-{m}-{d}'.format(y=date.year, m=date.month,
                                         d=date.day))
    # NASAのAPIから取得した画像をダウンロード。
    res = requests.get(pic.url)
    if res.status_code == 200:
        with open(image_name, 'wb') as file:
            file.write(res.content)
Exemplo n.º 3
0
def getApod(date):
    # Getting Picture of the day
    os.environ["NASA_API_KEY"] = "NASA_API_KEY"
    image = apod.apod(date)
    payload = image.url
    # Download the image using the URL in payload
    urllib.request.urlretrieve(payload, "ApodNasa.jpg")
    data = "{}*{}*{}".format(image.title, image.explanation, date)
    # print(data)
    return data
Exemplo n.º 4
0
def run():
    # Set up NASA API key
    os.environ["NASA_API_KEY"] = "K3JpH7ViIRRNcajPKb3LtMxIszuhHkL9DyhVvnuW"
    # Takes images from apod
    date = makedate()
    pagedate = date[2:4]+date[5:7]+date[8:10]
    page = "http://apod.nasa.gov/apod/ap"+pagedate+".html"
    apodim = apod.apod(date)
    apodim.page = page
    apodim.mytitle = maketitle(apodim)
    print apodim.mytitle
    return apodim
Exemplo n.º 5
0
# Uses a Python NASA API (see brendanv github repository)
# Note that API was installed with pip installer, but API
# code was changed to reflect different NASA API website

environ['NASA_API_KEY'] = "VSeA2cMgNPtUslwyxj1cSGztgo8ZLJhUkGyA2IZ1"

apodDay = datetime.datetime.now()

if (apodDay.hour < 9):
    apodDay = apodDay - datetime.timedelta(
        days=1)  # Pull yesterday's APOD if before 9am
# Convert date to YYYY-MM-DD format:
apodDate = apodDay.strftime("%Y-%m-%d")

# Get image source for NASA APOD website:
astroPod = nasaApod.apod(apodDate)
apodUrl = str(astroPod.url)
apodUrl2 = "https://api.nasa.gov/planetary/apod?api_key=" + "VSeA2cMgNPtUslwyxj1cSGztgo8ZLJhUkGyA2IZ1"
apodUrl3 = "https://apod.nasa.gov/apod/ap" + apodDay.strftime(
    '%y%m%d') + ".html"

http = urllib3.PoolManager(cert_reqs='CERT_REQUIRED', ca_certs=certifi.where())

# NASA API returns a JSON object, read contents into memory
jApod = requests.get(apodUrl2)
aPod = json.loads(jApod.text)

apodPage = http.request('GET', apodUrl3)
soup = BeautifulSoup(apodPage.data.decode('utf-8'), "html.parser")
yturl = ""
iframe = ""
Exemplo n.º 6
0
from nasa import apod
import os
import requests
from PIL import Image

os.environ['NASA_API_KEY'] = 'z0AbyDWDUTBz62emA5XsJbeqKiamrqN3kGNzKPFf'
picture = apod.apod('2019-05-26')
image = Image.open(requests.get(picture.url, stream=True).raw)
image.save(f'/Users/matej/Desktop/images_nasa/{picture.title}.jpg')
Exemplo n.º 7
0
    ptime = stime + prop * (etime - stime)

    return time.strftime(format, time.localtime(ptime))


def randomDate(start, end, prop):
    #return strTimeProp(start, end, '%m/%d/%Y', prop)
    return strTimeProp(start, end, '%Y-%m-%d', prop)


os.environ['NASA_API_KEY'] = 'sUMrj7lWaYKyQA5w0Zs0PPz9YhBtJ6Pt5cSHVCzK'

date = randomDate('1996-1-1', time.strftime('%Y-%m-%d'), random.random())

picture = apod.apod(date)

tweet = '#nasa ' + picture.title + ' Date : ' + date

if (len(tweet) < 276):
    ocL = len(picture.explanation)
    tL = len(tweet)
    tot = (ocL if ocL + tL <= 276 else 275 - tL)
    tweet += ' ' + picture.explanation[:tot] + "..."

auth = tweepy.OAuthHandler(C_KEY, C_SECRET)
auth.set_access_token(A_TOKEN, A_TOKEN_SECRET)
api = tweepy.API(auth)

filename = 'tempNasa.jpg'
request = requests.get(picture.url, stream=True)
from nasa import apod
import os
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import requests
from PIL import Image
import numpy as np

os.environ['NASA_API_KEY'] = 'z0AbyDWDUTBz62emA5XsJbeqKiamrqN3kGNzKPFf'
picture = apod.apod('2003-05-26')
print(picture.title)
image = Image.open(requests.get(picture.url, stream=True).raw)
img = np.array(image)
implt = plt.imshow(img)
plt.show()