Last active
February 22, 2020 00:35
-
-
Save aprilspeight/0fda02c5f9116279a3f23610b5bf53e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# modules to import | |
import requests | |
from twilio.rest import Client | |
import emoji | |
from datetime import date | |
# date variables | |
today = date.today() | |
today_converted = date(today.year, today.month, today.day) | |
target_date = date(2020, 1, 6) | |
delta = target_date - today_converted | |
# NASA GET request | |
response = requests.get('https://api.nasa.gov/planetary/apod?api_key=XXXXXX') | |
response_json = response.json() | |
# variables for the text message | |
picture = response_json['url'] | |
title = response_json['title'] | |
rocket = emoji.emojize(":rocket:") | |
# Twilio account credentials | |
account_sid = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' | |
auth_token = '9fxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' | |
client = Client(account_sid, auth_token) | |
# text message setup | |
message = client.messages \ | |
.create( | |
body=f'Today\'s picture is of: {title}! \n\n Btw...T{delta.days} days until we go to NASA! {rocket}', | |
from_='+1xxxxxxxxxx', | |
media_url=[f'{picture}'], | |
to='+1xxxxxxxxxx' | |
) | |
print(message.sid) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment