class aftership_track: #---------------------start of API poslaju tracker#--------------------- API_KEY = '1fcd696a-b4b9-4150-baca-6bcadd010a13' #get API object api = aftership.APIv4(API_KEY) #object constructor slug = 'pos-laju' #courier #number = 'ER028982330MY' #tracking number for testing purposes # gets list of supported couriers def get_courier(): couriers = api.couriers.all.get() return couriers def create_track(number): return api.trackings.post(tracking=dict(slug=slug, tracking_number=number, title="Test")) #{u'tracking': { ... }} def get_track(number): return api.trackings.get(slug, number, fields=['title', 'created_at']) #{u'tracking': { ... }} def delete_track(number): return api.trackings.delete(slug, number) #{u'tracking': { ... }} #---------------------End of API poslaju tracker#---------------------
def TestAPI(): api = aftership.APIv4('33ab0b24-106a-40e3-8220-4e5945d57c5e') # couriers = api.couriers.all.get() onetwo = '' slug = 'ups' number = '1Z6962EX0237423973' api.trackings.post(tracking=dict(slug=slug, tracking_number=number)) tracking = api.trackings[slug][number].get()['tracking'] test = 'asdfas'
class AfterShip(): aftershipApi = aftership.APIv4(constants.AFTERSHIP_API_KEY) def getAllCouriers(self): '''Returns the names of couriers Aftership supports''' return self.aftershipApi.couriers.all.get() def createShipment(self, slug, number, Title): '''Returns a dictionary of shipment information ''' return self.aftershipApi.trackings.post( tracking=dict(slug=slug, tracking_number=number, title="title")) def getTrackingInfo(self, slug, number): '''Returns the tracking information of a parcel''' return self.aftershipApi.trackings.get(slug, number)
#from core and TRANSACTION models from core.models import UserInfo from transactions.models import Transaction ##Adding email functionality (http://catherinetenajeros.blogspot.com/2013/03/send-mail.html) from django.core.mail import send_mail from django.template.loader import render_to_string #Import Messaging Stuff from django.contrib import messages from django_messages.models import Message from django_messages.forms import ComposeForm from django_messages.utils import format_quote, get_user_model, get_username_field from django_messages.views import notify_user_received_message #aftership import aftership AFTERSHIP_API_KEY = settings.AFTERSHIP_API_KEY #DEFINED IN SETTINGS.PY api = aftership.APIv4(AFTERSHIP_API_KEY) #Defined in settings.py #JMY NOTES - FOR CALLING THIS FROM PYTHONG BASH #NEED TO COPY AND PASTE THE DEFINITIOSN INTO PYTHONG, THEN # E.G., PRINT TRANS_AFTERSHIP_NOTARCHIVED[1].ID will print the ID for the first in the list, # PRINT TRANS_AFTERSHIP_NOTARCHIVED[1].tracking_info def watch_packages(specificuser_id=None): response_messages_list = [] todaydate = datetime.date.today() transactions_onaftership = Transaction.objects.filter(on_aftership=True) transactions_notcompleted = Transaction.objects.exclude( trans_complete=True) trans_aftership_notarchived = transactions_onaftership.exclude( trans_archived=True)
def __init__(self): self.client = zulip.Client(site="https://shehacks.zulipchat.com/api") self.api = aftership.APIv4('c82e624d-909f-4954-a99c-2f7a993a40d2') self.subscribe_all() print("done init")
def handle_tracking_result_intent(self, message): """ Find Package Details """ def extractNum(splitUtterance): for word in splitUtterance: try: extractedNumber = w2n.word_to_num(word) return extractedNumber except: isWord = word self.speak("error here") def addTrackingDetails(courierService, trackingNumber): self.speak("Searching for your package, Please wait") resultdetail = api.trackings.post( tracking=dict(slug=courierService, tracking_number=trackingNumber, title="Title")) filterTrackingCreateDetail(resultdetail, courierService, trackingNumber) def getTrackingDetails(courierService, trackingNumber): trackedParcelDetails = api.trackings.get(courierService, trackingNumber) self.enclosure.bus.emit( Message("trackingObject", {'desktop': { 'data': str(trackedParcelDetails) }})) filterTrackedDetail(trackedParcelDetails, courierService, trackingNumber) def filterTrackingCreateDetail(cobject, courierService, trackingNumber): tcID = cobject["tracking"]["id"] tcNumber = cobject["tracking"]["tracking_number"] tcCdate = cobject["tracking"]["created_at"] tcUdate = cobject["tracking"]["updated_at"] tcSlug = cobject["tracking"]["slug"] tcOrigin = cobject["tracking"]["origin_country_iso3"] tcDest = cobject["tracking"]["destination_country_iso3"] tcTag = cobject["tracking"]["tag"] resultMsg = "Your package with tracking number {0} created on date {1} updated on {2} with delivery service {3} from country of origin {4} to destination country {5} is currently {6}".format( tcNumber, tcCdate, tcUdate, tcSlug, tcOrigin, tcDest, tcTag) self.speak(resultMsg) getTrackingDetails(courierService, trackingNumber) def filterTrackedDetail(cobject, courierService, trackingNumber): LOGGER.info(cobject) removeTrackingDetails(courierService, trackingNumber) def removeTrackingDetails(courierService, trackingNumber): r = api.trackings.delete(courierService, trackingNumber) utterance = message.data.get('utterance').lower() utter = utterance.replace("-", "") splitUtterance = utter.split() convertedList = [] for idx, word in enumerate(splitUtterance): try: convertedList.append(str(w2n.word_to_num(word))) except: convertedList.append(word) LOGGER.info(convertedList) trackingNumber = ''.join(convertedList) api = aftership.APIv4('eae7efb7-6ac4-4b89-aeec-e620294cad33') addTrackingDetails(courierService, trackingNumber)
import aftership as aftership api = aftership.APIv4("8a4aab03-8132-4fae-aca8-48c054964e14") #couriers = api.couriers.all.get() #print couriers #slug = 'dhl-global-mail' #number = 'RX386462306DE' slug = 'dtdc' number = 'R26561823' print api.trackings.post(tracking=dict(slug=slug, tracking_number=number, title="Title")) print api.trackings.get(slug, number, fields=['tag','location','updated_at','checkpoint_time']) print api.trackings.get(slug, number) # working code to fetch courier list # ans = aftership.Courier.all() # for k, v in ans.iteritems(): # for i in range(len(v)): # print v[i]['slug']+" "+ v[i]['name'] #print aftership.Tracking.get() #print aftership.Tracking.get('RX386462306DE','dhl-global-mail') #print aftership.Tracking.last_checkpoint('RX386462306DE','dhl')