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

from tabulate import tabulate

from Trenitalia import Trenitalia

if __name__ == "__main__":
    TP = Trenitalia({"dep": "Firenze S. M. Novella",
                     "arr": "Milano Centrale",
                     "date": "21-11-2014",
                     # "time": "07",
                     "nAdults": "1",
                     "code": "9502"})

    RES = TP.find_page()

    for train in RES:
        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)

@@ -79,71 +79,340 @@
 ate%0A
-%0Afrom Trenitalia import Trenitalia%0A%0Aif __name__ == %22__main__%22:%0A
+from datetime import date, timedelta%0A%0Afrom Trenitalia import Trenitalia%0A%0Adef daterange(start_date, end_date):%0A    for n in range(int ((end_date - start_date).days)):%0A        yield start_date + timedelta(n)%0A%0Aif __name__ == %22__main__%22:%0A    START = date.today()%0A    END = START + timedelta(30)%0A%0A    for d in daterange(START, END):%0A    
     
@@ -481,16 +481,20 @@
         
+    
 %22arr%22: %22
@@ -536,16 +536,20 @@
     
+    
 %22date%22: 
 %2221-
@@ -548,22 +548,35 @@
 e%22: 
-%2221-11-2014%22,%0A
+d.strftime(%22%25d-%25m-%25Y%22),%0A   
     
@@ -592,17 +592,16 @@
         
-#
  %22time%22:
@@ -607,16 +607,20 @@
 : %2207%22,%0A
+    
         
@@ -669,16 +669,20 @@
         
+  
+  
 %22code%22: 
@@ -691,16 +691,20 @@
 502%22%7D)%0A%0A
+    
     RES 
@@ -724,247 +724,135 @@
 e()%0A
-%0A
+ 
     
-for train in RES:%0A        print %22Train Code:%5Ct%22 + train%5B%22trainCode%22%5D%0A        print %22Departure:%5Ct%22 + train%5B%22depTime%22%5D%0A        print %22Arrival:%5Ct%22 + train%5B%22arrTime%22%5D%0A        print %22Duration:%5Ct%22 + train%5B%22duration%22%5D%0A        table = list()%0A
+   if len(RES) %3E 0:%0A            train = RES%5B0%5D%0A            table = list()%0A            print d.strftime(%22%25A %25d %25B %25Y%22)%0A    
     
@@ -898,15 +898,15 @@
     
+   
-row = %5B
+ if 
 pr%5B%22
@@ -915,18 +915,45 @@
 reType%22%5D
-%5D%0A
+ == %22SUPER ECONOMY%22:%0A        
         
@@ -1003,18 +1003,131 @@
     
-row.append
+        if x%5B%22price%22%5D != %22N/A%22:%0A                            print (d.strftime(%22%25A %25d %25B %25Y%22) + %22 %22 + x%5B%22comfort%22%5D+ %22 %22 +str
 (x%5B%22
@@ -1134,16 +1134,17 @@
 price%22%5D)
+)
 %0A       
@@ -1152,87 +1152,192 @@
     
-table.append(row)%0A        print%0A        print tabulate(table, headers=TP.COMFORTS)
+                break%0A                    else:%0A                        continue%0A                    break%0A            else:%0A                continue%0A            break%0A    print %22The end%22
 %0A

find the first SUPER ECONOMY solution