avance lectura archivo proto
parent
cb77216f2f
commit
b0fe0848b8
|
@ -70,7 +70,6 @@ Content-Type: application/json
|
|||
|
||||
|
||||
###
|
||||
|
||||
GET {{server}}/lineas/proto?id_paradero=45086
|
||||
Authorization: Bearer {{token}}
|
||||
|
||||
|
@ -78,6 +77,5 @@ Authorization: Bearer {{token}}
|
|||
|
||||
|
||||
###
|
||||
|
||||
GET {{server}}/proto/
|
||||
GET {{server}}/lineas/buses_proto/?id_linea=730-0
|
||||
Authorization: Bearer {{token}}
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
@server = http://localhost:3000/api
|
||||
@token = {{login.response.body.$.token}}
|
||||
|
||||
###
|
||||
# @name login
|
||||
POST {{server}}/auth/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"username": "usuario1",
|
||||
"password": "usuario1"
|
||||
}
|
||||
|
||||
###
|
||||
# @name protodata
|
||||
GET {{server}}/proto/status
|
||||
Authorization: Bearer {{token}}
|
|
@ -5,6 +5,7 @@ from api.views import usuario, auth, aplicacion, tipo, persona, comuna, region,
|
|||
from api.views import mapa, linea, letrero_lur, operador
|
||||
from api.views import paradero_imagen, linea_paradero
|
||||
from api.views import dispositivo
|
||||
from api.views import proto
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register('aplicaciones', aplicacion.AplicacionViewSet)
|
||||
|
@ -30,8 +31,8 @@ router.register('rolyaplicacion', rolaplicacion.RolAplicacionViewSet, basename='
|
|||
urlpatterns = [
|
||||
path('', include(router.urls)),
|
||||
path('auth/', auth.jwt_login, name='auth'),
|
||||
# path('proto/', proto.status, name='proto_status'),
|
||||
path('mapas/paraderos/', mapa.paraderos, name='mapa-paraderos'),
|
||||
path('mapas/rutas/', mapa.rutas, name='mapa-rutas'),
|
||||
path('paraderos/info-public/<int:pk>/', paradero.info_public, name='paradero-infopublic'),
|
||||
path('proto/status/', proto.status, name='proto_status'),
|
||||
]
|
||||
|
|
Binary file not shown.
File diff suppressed because one or more lines are too long
|
@ -6,6 +6,7 @@ from django_filters.rest_framework import DjangoFilterBackend
|
|||
from django.db import connection
|
||||
from .. import models, serializers
|
||||
from django.http import JsonResponse
|
||||
import logging
|
||||
|
||||
class LineaViewSet(viewsets.ModelViewSet):
|
||||
queryset = models.Linea.objects.all()
|
||||
|
@ -78,6 +79,12 @@ class LineaViewSet(viewsets.ModelViewSet):
|
|||
def buses_proto(self, request, pk=None):
|
||||
pk = request.GET['id_linea']
|
||||
|
||||
linea = models.Linea.objects \
|
||||
.filter(id_linea=pk) \
|
||||
.first()
|
||||
|
||||
logging.error(linea)
|
||||
|
||||
detalle_buses = []
|
||||
paraderos = models.Paradero.objects \
|
||||
.filter(vigente=True, lineaparadero__id_linea=pk) \
|
||||
|
@ -89,13 +96,14 @@ class LineaViewSet(viewsets.ModelViewSet):
|
|||
where stop_id = %s"
|
||||
|
||||
for p in paraderos:
|
||||
params = [ p['id_paradero'] ]
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute(query, params)
|
||||
row = cursor.fetchone()
|
||||
id_paradero = p['id_paradero']
|
||||
|
||||
if row != None:
|
||||
buses = list(filter(lambda linea: linea['linea'] == pk, row[0]))
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute(query, [ id_paradero ])
|
||||
datajson = cursor.fetchone()
|
||||
|
||||
if datajson != None:
|
||||
buses = list(filter(lambda rowjson: rowjson['Descripcion'] == linea.route_short_name, datajson[0]))
|
||||
for bus in buses:
|
||||
for llegada in bus['Llegadas']:
|
||||
data_bus = {
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from rest_framework.decorators import action, api_view
|
||||
from api.utils import gtfs_realtime_pb2
|
||||
from project.settings import BASE_DIR
|
||||
from django.http import JsonResponse
|
||||
import logging
|
||||
|
||||
def status(request):
|
||||
nombre_archivo_proto = f'{BASE_DIR}/api/utils/demo.proto'
|
||||
with open(nombre_archivo_proto, 'rb') as proto_file:
|
||||
feed = gtfs_realtime_pb2.FeedMessage()
|
||||
feed.ParseFromString(proto_file.read())
|
||||
|
||||
data = {} #get_object(feed)
|
||||
# logging.error(dir(feed))
|
||||
# logging.error(feed.header)
|
||||
# logging.error(dir(feed.entity))
|
||||
logging.error(feed.entity[0])
|
||||
# logging.error(dir(feed.entity[0].trip_update))
|
||||
|
||||
return JsonResponse(data, safe=False)
|
||||
|
||||
|
||||
def get_object(obj1, obj2 = {}, level = 1):
|
||||
attributes = dir(obj1)
|
||||
for attr in attributes:
|
||||
if attr[0:1] != '_':
|
||||
try:
|
||||
for elem in obj1[attr]:
|
||||
logging.error(elem)
|
||||
except:
|
||||
logging.error(attr)
|
||||
pass
|
||||
return obj2
|
||||
|
||||
|
||||
def is_subscriptable(obj):
|
||||
return hasattr(obj, '__getitem__')
|
||||
|
||||
def is_iterable(obj):
|
||||
try:
|
||||
iter(obj)
|
||||
return True
|
||||
except TypeError:
|
||||
return False
|
|
@ -8,4 +8,5 @@ python-decouple
|
|||
PyJWT
|
||||
pymongo
|
||||
Pillow
|
||||
openpyxl
|
||||
openpyxl
|
||||
google
|
Loading…
Reference in New Issue