def Result(request): name = request.GET.get('name') email = request.GET.get('emf') track_number1 = request.GET.get('trn') company = request.GET.get('company') for item in trackingmore.get_all_trackings()["data"]["items"]: if item["tracking_number"] == track_number1: trackingmore.delete_tracking_item(company, track_number1) td = trackingmore.create_tracking_data(company, track_number1) track_data = trackingmore.realtime_tracking(td) track_info1 = track_data["items"][0]["origin_info"]["trackinfo"] lis = [] for item1 in track_info1: lis.append(item1) context = { 'track_number': track_data["items"][0]["tracking_number"], 'current_status': track_data["items"][0]["status"], 'last_event': track_data["items"][0]["lastEvent"], #'track_info':track_data["items"][0]["origin_info"]["trackinfo"] 'lis': lis, 'name': name, } return render(request, 'trackapp/Result.html', context)
def index(): trackingmore.set_api_key('fbbf2fc8-176b-4e23-aaec-8dac6e110150') print("lll") var1 = trackingmore.create_tracking_data('delhivery', '379211877610') print("") s = trackingmore.realtime_tracking(var1) print("lll") return render_template('test.html', **locals())
def get_or_create_tracking_item(carrier, code): try: tracking_data = trackingmore.create_tracking_data(carrier, code) trackingmore.create_tracking_item(tracking_data) tracking_data = trackingmore.get_tracking_item(carrier, code) except trackingmore.trackingmore.TrackingMoreAPIException as e: if e.err_code == 4016: # Already exists tracking_data = trackingmore.get_tracking_item(carrier, code) else: raise e return tracking_data
def get_or_create_tracking_item(carrier, code): print(carrier) try: tracking_data = trackingmore.get_tracking_item(carrier, code) except trackingmore.trackingmore.TrackingMoreAPIException as e: if e.err_code == 4031 or e.err_code == 4017: tracking_data = trackingmore.create_tracking_data(carrier, code) trackingmore.create_tracking_item(tracking_data) tracking_data = trackingmore.get_tracking_item(carrier, code) else: raise e return tracking_data
def get(code, times): try: td = trackingmore.create_tracking_data('cainiao', code) trackingmore.create_tracking_item(td) except trackingmore.trackingmore.TrackingMoreAPIException as e: if e.err_code == 4019 or e.err_code == 4021: return status.OFFLINE if e.err_code == 4016: # Already exists try: td = trackingmore.get_tracking_item('cainiao', code) except trackingmore.trackingmore.TrackingMoreAPIException as e: if e.err_code == 4019 or e.err_code == 4021: return status.OFFLINE print(td) if td['status'] == 'notfound': return status.NOT_FOUND_TM elif len(td) < 10: return status.OFFLINE return formato_obj(td)
import trackingmore import pprint p = pprint.PrettyPrinter() trackingmore.set_api_key('32de660c-b478-40f1-8c75-d5ada104be82') var1 = trackingmore.create_tracking_data('delhivery', '379211877610') s = trackingmore.realtime_tracking(var1) p.pprint(s)