Skip to content

Commit

Permalink
Tracking more bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielRF committed Oct 7, 2019
1 parent efbccb9 commit d4131ed
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
50 changes: 50 additions & 0 deletions apigeartrack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import configparser
import json
import requests
import status
import trackingmore
import sys

config = configparser.ConfigParser()
config.sections()
config.read('bot.conf')

def getcorreioscode(carrier, code):
url = ('https://geartrack.pt/api/{}?id={}'.format(carrier, code))
r = requests.get(url)
conteudo = str(r.content.decode('UTF-8'))
a = json.loads(conteudo)
if a['destinyId']:
return(a['destinyId'])


def getstatus(code, retries):
carrier = 'cainiao'
code = 'LP00139186175797'
url = ('https://geartrack.pt/api/{}?id={}'.format(carrier, code))
r = requests.get(url)
conteudo = str(r.content.decode('UTF-8'))
a = json.loads(conteudo)
#print(a)
print(formato_obj(a))

def formato_obj(json):
stats = []
stats.append(str(u'\U0001F4EE') + ' <b>' + json['id'] + '</b>')
tabela = json['states']
mensagem = ''
for evento in reversed(tabela):
data = evento['date']
situacao = evento['state']
observacao = ''
mensagem = ('Data: {}' +
'\nSituacao: <b>{}</b>'
).format(data, situacao)
stats.append(mensagem)
if json['destinyId']:
stats.append('Pacote recebido nos Correios.\nCódigo: /' + json['destinyId'])
return stats


if __name__ == '__main__':
getstatus(sys.argv[1], 0)
2 changes: 1 addition & 1 deletion apitrackingmore.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_carriers(code):
if type(cursor['carrier']) is dict:
return [cursor['carrier']]
return cursor['carrier']
except:
except KeyError:
carriers = trackingmore.detect_carrier_from_code(code)
carriers.sort(key=lambda carrier: carrier['code'])
set_carrier_db(code, carriers)
Expand Down

0 comments on commit d4131ed

Please sign in to comment.