PNR Script CODING HELP

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    PNR Script CODING HELP

    from HTMLParser import HTMLParser
    import httplib

    """ Exception Class """
    class NoPNRException (Exception):
    def __init__ ( self ):
    pass
    def __str__ ( self ):
    return "No Such PNR Number"

    """ Makes and HTTP POST request to indianrail.gov.in and fetches the
    html """
    class Requester:
    def result ( self, pnri, pnrl ):
    SoapMessage =
    "lccp_pnrno1="+pnri+"&lccp_pnrno2="+pnrl+"&submitp nr=Wait+for+PNR+status%21"

    webservice = httplib.HTTP("www.indianrail.gov.in")
    webservice.putrequest("POST", "/cgi_bin/inet_pnrstat_cgi.cgi")
    webservice.putheader("User-Agent", "Mozilla/5.0 (X11; U; Linux
    i686; en-US; rv:1.8.1.13) Gecko/20080325 Nothing Authentic Bot.")
    webservice.putheader("Content-type", "text/xml; charset=\"UTF-8\"")
    webservice.putheader("Content-length", "%d" % len(SoapMessage))
    webservice.endheaders()
    webservice.send(SoapMessage)

    statuscode, statusmessage, header = webservice.getreply()
    res = webservice.getfile().read()
    return res


    """ Parses the result returned by indianrail """
    class MyHTMLParser (HTMLParser):
    def handle_data ( self, data ):
    if data == "\n":
    return
    if "FLUSHED" in data:
    raise NoPNRException
    try:
    if self.previous == "PNR Number":
    print "PNR:", data
    self.answer.append ( data )
    if self.previous == "Charting":
    print "Chart:", data.strip ()
    self.answer.append ( data.strip () )
    except:
    self.previous = ""
    self.answer = []

    try:
    if self.start < 9 and self.start != 0:
    print "Stat:", data
    self.answer.append ( data )
    self.start += 1
    except:
    self.start = 0

    try:
    if self.poll == "true" and self.fieldctr < 2:
    print "Passenger", data
    self.answer.append ( data )
    self.fieldctr += 1
    if self.fieldctr == 2:
    self.fieldctr = 0
    self.poll = "false"
    except AttributeError:
    self.poll = "false"
    self.fieldctr = 0


    for i in [ "1", "2", "3", "4", "5", "6" ]:
    if "Passenger "+i in data:
    self.answer.append ( "Passenger " + i )
    self.poll = "true"

    if "PNR Number" in data:
    self.previous = "PNR Number"
    elif "Charting Status" in data:
    self.previous = "Charting"
    else:
    self.previous = ""

    if data == "1":
    self.start = 1
    def list ( self ):
    return self.answer

    """ Test Case """
    a = MyHTMLParser ()
    try:
    a.feed ( Requester().result ( "225", "0199127" ) )
    except NoPNRException:
    print 'NoSuchPNRNumber'
    /////////////////////////////////////////////////////////////////////////
    i found this script via google ,,,,any body plz make it in html page

    #2
    Its illelgal to use the script without getting permissions from Indiarail..!
    So try it at ur own risk.

    Comment


      #3
      i knw bt i will not use commercial

      Comment

      Working...
      X