This commit is contained in:
Jan Kiljanski 2024-06-02 12:19:14 +02:00
commit 26461250c3
2 changed files with 27 additions and 11 deletions

View File

@ -1,4 +1,5 @@
import pandas as pd
import os
class GTFS:
def __init__(self, folder_path):
@ -27,7 +28,7 @@ class GTFS:
try:
return pd.read_csv(self.file_path)
except FileNotFoundError:
return None
return pd.DataFrame()
class Agency(GTFSFile):
def __init__(self, folder_path):
@ -81,6 +82,29 @@ class GTFS:
def __init__(self, folder_path):
super().__init__(folder_path, 'feed_info')
def get_files(self):
return [attr for attr in list(set(dir(self)) - set(dir(GTFS))) if isinstance(getattr(self,attr),self.GTFSFile)]
def get_fields(self, name):
file = getattr(self, name)
if not file:
return None
return list(set(dir(file)) - set(dir(GTFSFile)))
def export(self, path, dirname):
path = f"{os.path.normpath(path)}/{dirname}"
if not os.path.exists(path):
os.mkdir(path)
print(self.get_files())
for name in self.get_files():
df = getattr(self, name).data
fpath = f"{path}/{name}.txt"
# print(f"name: {name}")
print(name)
df.to_csv(fpath, index=False)
def validate(self):
self.validate_agency()
self.validate_stops()

View File

@ -1,16 +1,8 @@
from django.shortcuts import render
from django.http import HttpResponse
from django.template import loader
from .models import Agency, Stop, Route, Trip, StopTime, Calendar, CalendarDate, FareAttribute, FareRule, Shape, Frequency, Transfer, FeedInfo
def index(request):
return HttpResponse("Test")
def testing(request):
template = loader.get_template('testing.html')
context = {
'fruits': ['Apple', 'Banana', 'Cherry'],
}
return HttpResponse(template.render(context, request))
context = {}
return HttpResponse(request, "templates/map.html", context)