Created
March 22, 2017 21:40
-
-
Save reginaldojunior/c5e60e41b01114b1c60ca372f276c81a to your computer and use it in GitHub Desktop.
script-python-requests.py
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import smtplib | |
import requests | |
import time | |
from email.mime.text import MIMEText | |
def main(): | |
url = "http://correios.plugg.to/v1/shipping" | |
payload = "{\n \"destination_postalcode\":\"07252015\",\n \"destination_state\":null,\n \"user_id\":907,\n \"origin_postalcode\":\"74563120\",\n \"origin_state\":\"GO\",\n \"origin_city\":\"GOIAS\",\n \"origin_country\":\"BR\",\n \"products\":[\n {\n \"weight\":0.4,\n \"height\":6,\n \"length\":30,\n \"width\":20,\n \"unit_price\":83,\n \"sku\":\"83002\",\n \"id\":\"57db0c0d620449e40b831ab5\",\n \"quantity\":\"1\"\n }\n ]\n}" | |
headers = { | |
'content-type': "application/json", | |
} | |
start = time.time() | |
response = requests.request("POST", url, data=payload, headers=headers) | |
if response.elapsed.total_seconds() > 0.3: | |
send_mail() | |
if response.status_code != 200: | |
send_mail() | |
def send_mail(): | |
fromaddr = 'reginaldo.junior@plugg.to' | |
toaddrs = 'reginaldo.junior@plugg.to' | |
msg = MIMEText("Existe mais de 5 mil notificações no mercado livre com status 0 ou 3") | |
msg['From'] = fromaddr | |
msg['To'] = toaddrs | |
msg['Subject'] = 'Correios com processamento errado ou lento' | |
username = 'suporte@thirdlevel.com.br' | |
password = 'Go@pluggto2016' | |
server = smtplib.SMTP('smtp.gmail.com') | |
server.starttls() | |
server.login(username, password) | |
server.sendmail(fromaddr, toaddrs, msg.as_string()) | |
server.quit() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment