Sms service api
Sent: Lau 05. Feb 2022 05:17
Kóði: Velja allt
import requests
from Auth import auth
from latnlong import find_location
from twilio.rest import Client
OWM_ENDPOINT = auth["end_point"]
# lets find our location, if nothing given a default will be presented, based on the location of your phone.
# returns tuples with 2 decimal and 1 function.
(latn,lonn,language) = find_location()
#the information i am looking for
parameters = {
"lat": latn,
"lon": lonn,
"appid":auth["api_key"],
"exclude": "current,minutely,daily"
}
#pipe that thing to our endpoint
response = requests.get(OWM_ENDPOINT,params=parameters)
# please let me know if something went wrong
response.raise_for_status()
weather_data = response.json()
# function that only looks out for rain drops
def find_for_rain(weather_data):
for index in weather_data["hourly"][:12]:
for weather in index["weather"]:
if weather["id"] < 700:
return True
return False
#for example calling the rain function
# will give us a message that, it found rain drops
if find_for_rain(weather_data):
client = Client(auth["twilacc_sid"], auth["twil_token"])
message = client.messages \
.create(
#language function will try to translate the text into whatever language the user wanted
body=f"{auth['api_name']}: {language('it's going to rain')},
from_=auth["api_number"],
to=auth["my_number"])
er ad bua simple forrit sem mun lata mig vita. Hvernig vedrid verdur naesta dag.
vitidi um odyrara leid eda okeypis, hef heyrt um telegram en vitidi um eithvad annad?
twilio frekar dyrt, finnst mer.