import csv
import sys

# agency.txt done
# feed_info.txt nothing to change

# calendar_dates.txt depends on service_id.
# routes.txt depends on agency.txt
# shapes.txt depends on trips.txt
# stops.txt depends on stop_times.txt
# stop_times.txt depends on trip_id.
# transfers.txt depends on stop_id from and to, routes.
# trips.txt contains shape_id, also route_id to trip_id.


def clean_agency_file(*agencies):
    with open('agency.txt', 'r') as f:
        reader = csv.reader(f)
        filtered_rows = []
        filtered_rows.append(next(reader))

        for row in reader:
            if row[0] in agencies:
                filtered_rows.append(row)

    with open('cleaned/agency.txt', 'w') as f:
        writer = csv.writer(f)
        writer.writerows(filtered_rows)


def main():
    agencies = sys.argv[1:]
    clean_agency_file(*agencies)


if __name__ == '__main__':
    main()

@@ -772,16 +772,416 @@
 rows)%0A%0A%0A
+def clean_routes_file(*agencies):%0A    with open('routes.txt', 'r') as f:%0A        reader = csv.reader(f)%0A        filtered_rows = %5B%5D%0A        filtered_rows.append(next(reader))%0A%0A        for row in reader:%0A            if row%5B1%5D in agencies:%0A                filtered_rows.append(row)%0A%0A    with open('cleaned/routes.txt', 'w') as f:%0A        writer = csv.writer(f)%0A        writer.writerows(filtered_rows)%0A%0A%0A
 def main
@@ -1245,16 +1245,48 @@
 encies)%0A
+    clean_routes_file(*agencies)
 %0A%0Aif __n

Clean the routes.txt