Last active
February 22, 2020 00:37
-
-
Save aprilspeight/4280bb64cc1248284f488daa7dee2761 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 datetime | |
import logging | |
import azure.functions as func | |
import requests | |
from datetime import date | |
from twilio.rest import Client | |
import emoji | |
# Twilio credentials | |
account_sid = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' | |
auth_token = '9fxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' | |
client = Client(account_sid, auth_token) | |
# main function - add the Twilio logic here | |
def main(mytimer: func.TimerRequest) -> None: | |
utc_timestamp = datetime.datetime.utcnow().replace( | |
tzinfo=datetime.timezone.utc).isoformat() | |
if mytimer.past_due: | |
logging.info('The timer is past due!') | |
logging.info('Python timer trigger function ran at %s', utc_timestamp) | |
today = date.today() | |
today_converted = date(today.year, today.month, today.day) | |
target_date = date(2020, 1, 6) | |
delta = target_date - target_converted | |
response = requests.get('https://api.nasa.gov/planetary/apod?api_key=XXXXXX') | |
response_json = response.json() | |
title = response_json['title'] | |
rocket = emoji.emojize(":rocket:") | |
picture = response_json['url'] | |
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