Skip to content

Instantly share code, notes, and snippets.

@reginaldojunior
Created March 22, 2017 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reginaldojunior/c5e60e41b01114b1c60ca372f276c81a to your computer and use it in GitHub Desktop.
Save reginaldojunior/c5e60e41b01114b1c60ca372f276c81a to your computer and use it in GitHub Desktop.
script-python-requests.py
#!/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