#!/usr/bin/env python
"""Trenitalia test module"""

from tabulate import tabulate

from Trenitalia import Trenitalia

if __name__ == "__main__":
    MYTRAINCODE = "9553"
    TP = Trenitalia()

    RES = TP.find_page({"dep": "Milano Centrale",
                        "arr": "Firenze S. M. Novella",
                        "date": "18-10-2014",
                        "time": "18",
                        "nAdults": "1"})

    for train in RES:
        if train["trainCode"] == MYTRAINCODE:
            print "Train Code:\t" + train["trainCode"]
            print "Departure:\t" + train["depTime"]
            print "Arrival:\t" + train["arrTime"]
            print "Duration:\t" + train["duration"]
            table = list()
            for pr in train["prices"]:
                row = [pr["fareType"]]
                for x in pr["farePrices"]:
                    row.append(x["price"])
                table.append(row)
            print
            print tabulate(table, headers=TP.COMFORTS)

@@ -146,105 +146,57 @@
     
-MYTRAINCODE = %229553%22%0A    TP = Trenitalia()%0A%0A    RES = TP.find_page(%7B%22dep%22: %22Milano Centrale%22,%0A   
+TP = Trenitalia(%7B%22dep%22: %22Firenze S. M. Novella%22,%0A
     
@@ -224,35 +224,26 @@
 %22: %22
-Firenze S. M. Novella%22,%0A   
+Milano Centrale%22,%0A
     
@@ -272,13 +272,13 @@
 %22: %22
+2
 1
-8
 -1
-0
+1
 -201
@@ -302,18 +302,17 @@
         
-  
+#
  %22time%22:
@@ -317,16 +317,13 @@
 %22: %22
-18
+07
 %22,%0A
-   
     
@@ -357,84 +357,97 @@
  %221%22
-%7D)%0A
+,
 %0A    
-for train in RES:%0A        if train%5B%22trainCode%22%5D == MYTRAINCODE:%0A    
+                 %22code%22: %229502%22%7D)%0A%0A    RES = TP.find_page()%0A%0A    for train in RES:%0A
     
@@ -493,36 +493,32 @@
 nCode%22%5D%0A        
-   
- 
 print %22Departure
@@ -545,28 +545,24 @@
 e%22%5D%0A        
-    
 print %22Arriv
@@ -591,28 +591,24 @@
 e%22%5D%0A        
-   
- 
 print %22Durat
@@ -639,28 +639,24 @@
 n%22%5D%0A        
-    
 table = list
@@ -658,20 +658,16 @@
  list()%0A
-    
         
@@ -705,20 +705,16 @@
         
-    
 row = %5Bp
@@ -728,20 +728,16 @@
 Type%22%5D%5D%0A
-    
         
@@ -783,20 +783,16 @@
         
-    
 row.appe
@@ -806,20 +806,16 @@
 rice%22%5D)%0A
-    
         
@@ -848,22 +848,14 @@
     
-    
 print%0A
-    
     

put train code in the search parameters