Ejemplo n.º 1
0
def main():
    rjs = json.load(open('routes_detail.json', 'r'))
    from routes.models import Route, RouteStage
    from stages.models import Stage

    # For every route number in the dictionary
    for rj in rjs:

        # if the route is present already, edit it
        if not Route.objects.filter(city='delhi').filter(mtc_name=rj):
            new_route = Route()
        else:
            new_route = Route.objects.filter(city='delhi').get(mtc_name=rj)

        # Add/Reset details of the route
        new_route.display_name = rj
        new_route.city = 'delhi'
        new_route.mtc_name = rj
        new_route.types = "O"  #FIXME: Classify routes under appropriate types
        new_route.fare = -1  #TODO: Scrape fare data
        new_route.time = -1  #TODO: Scrape time data
        new_route.slug = slugify(rj)

        # Add new/existing stage object as route's start stage
        try:
            sstage = rjs[rj][0]
            ssobj = Stage.objects.filter(city='delhi').get(mtc_name=sstage)
        except Stage.DoesNotExist:
            ssobj = Stage()
            ssobj.mtc_name = sstage
            ssobj.display_name = sstage
            ssobj.city = 'delhi'
            ssobj.save()
        new_route.start = ssobj

        # Add new/existing stage object as route's end stage
        try:
            estage = rjs[rj][-1]
            esobj = Stage.objects.filter(city='delhi').get(mtc_name=estage)
        except Stage.DoesNotExist:
            esobj = Stage()
            esobj.mtc_name = estage
            esobj.display_name = estage
            esobj.city = 'delhi'
            esobj.save()
        new_route.end = esobj

        # Save the route
        new_route.save()

        # Add RouteStage object for every stage in route
        sequence = 100
        for stage in rjs[rj]:

            # Get or create stage object
            try:
                sobj = Stage.objects.filter(city='delhi').get(mtc_name=stage)
            except Stage.DoesNotExist:
                sobj = Stage()
                sobj.mtc_name = stage
                sobj.display_name = stage
                sobj.city = 'delhi'
                sobj.save()

            # Get or create RouteStage object
            try:
                rs = RouteStage.objects.filter(route=new_route).get(
                    stage__display_name=stage)
            except RouteStage.DoesNotExist:
                rs = RouteStage()
            rs = RouteStage()
            rs.route = new_route
            rs.stage = sobj
            rs.sequence = sequence
            rs.save()

            # Increment sequence of stage
            sequence += 100
Ejemplo n.º 2
0
def main():
   rds = json.load(open('routes_detail.json', 'r'))
   from routes.models import Route, RouteStage, ROUTE_TYPE_MAPPING
   from stages.models import Stage
   
   for r in Route.objects.filter(city=CITY):
      r.city = CITY + '_old'
      r.save()

   # For every route number in the dictionary
   for mtc_name in rds:
      display_name, slug = resolve_route_name(mtc_name)
      rd = rds[mtc_name]
      if rd["source"] is None or rd["destination"] is None or len(rd["stages"]) == 0:
         #print "Route %s skipped (Reason: Incomplete)" % mtc_name
         continue # Skipping Incomplete routes
      service_type = rd["service_type"]
      s_type = MTC_TYPE_REVERSE_MAP[service_type]
      
      # if the route is present already, edit it
      if not Route.objects.filter(city=CITY).filter(slug=slug):
         r = Route()
      else:
         r = Route.objects.filter(city=CITY).get(slug=slug)
         
      # Add/Reset details of the route
      r.display_name = display_name
      r.city = CITY
      r.mtc_name = mtc_name
      if r.types is None or r.types == "":
         r.types = s_type
      elif s_type not in r.types.split(','):
         r.types = r.types + "," + s_type
      r.fare = -1 #TODO: Remove fare data
      r.time = -1 #TODO: Remove time data
      r.slug = slugify(slug)

      # Add new/existing stage object as route's start stage
      sstage = rd["source"]
      try:
         ssobj = Stage.objects.get(city=CITY, mtc_name = sstage)
      except Stage.DoesNotExist:
         ssobj = Stage()
         ssobj.display_name = sstage.title()
         ssobj.city = CITY
         ssobj.mtc_name = sstage
         ssobj.save()
      r.start = ssobj
      
      # Add new/existing stage object as route's end stage
      estage = rd["destination"]
      try:
         esobj = Stage.objects.get(city=CITY, mtc_name = estage)
      except Stage.DoesNotExist:
         esobj = Stage()
         esobj.display_name = estage.title()
         esobj.city = CITY
         esobj.mtc_name = estage
         esobj.save()
      r.end = esobj
      
      # Save the route
      r.save()
      
      # Add RouteStage object for every stage in route
      sequence = 100
      for stage in rd["stages"]:
         
         # Get or create stage object
         try:
            sobj = Stage.objects.get(city=CITY, mtc_name = stage)
         except Stage.DoesNotExist:
            sobj = Stage()
            sobj.display_name = stage.title()
            sobj.city = CITY
            sobj.mtc_name = stage
            sobj.save()
         
         # Get or create RouteStage object
         try:
            rs = RouteStage.objects.filter(route=r).get(stage=sobj)
         except RouteStage.DoesNotExist:
            rs = RouteStage()
         rs.route = r
         rs.stage = sobj
         rs.sequence = sequence
         rs.save()
         
         # Increment sequence of stage
         sequence += 100
Ejemplo n.º 3
0
def main():
   rjs = json.load(open('routes_detail.json', 'r'))
   from routes.models import Route, RouteStage
   from stages.models import Stage
   
   # For every route number in the dictionary
   for rj in rjs:
      
      # if the route is present already, edit it
      if not Route.objects.filter(city='delhi').filter(mtc_name=rj):
         new_route = Route()
      else:
         new_route = Route.objects.filter(city='delhi').get(mtc_name=rj)
         
      # Add/Reset details of the route
      new_route.display_name = rj
      new_route.city = 'delhi'
      new_route.mtc_name = rj
      new_route.types = "O" #FIXME: Classify routes under appropriate types
      new_route.fare = -1 #TODO: Scrape fare data
      new_route.time = -1 #TODO: Scrape time data
      new_route.slug = slugify(rj)

      # Add new/existing stage object as route's start stage
      try:
         sstage = rjs[rj][0]
         ssobj = Stage.objects.filter(city='delhi').get(mtc_name=sstage)
      except Stage.DoesNotExist:
         ssobj = Stage()
         ssobj.mtc_name = sstage
         ssobj.display_name = sstage
         ssobj.city = 'delhi'
         ssobj.save()
      new_route.start = ssobj
      
      # Add new/existing stage object as route's end stage
      try:
         estage = rjs[rj][-1]
         esobj = Stage.objects.filter(city='delhi').get(mtc_name=estage)
      except Stage.DoesNotExist:
         esobj = Stage()
         esobj.mtc_name = estage
         esobj.display_name = estage
         esobj.city = 'delhi'
         esobj.save()
      new_route.end = esobj

      # Save the route
      new_route.save()
      
      # Add RouteStage object for every stage in route
      sequence = 100
      for stage in rjs[rj]:
         
         # Get or create stage object
         try:
            sobj = Stage.objects.filter(city='delhi').get(mtc_name=stage)
         except Stage.DoesNotExist:
            sobj = Stage()
            sobj.mtc_name = stage
            sobj.display_name = stage
            sobj.city = 'delhi'
            sobj.save()
         
         # Get or create RouteStage object
         try:
            rs = RouteStage.objects.filter(route=new_route).get(stage__display_name=stage)
         except RouteStage.DoesNotExist:
            rs = RouteStage()
         rs = RouteStage()
         rs.route = new_route
         rs.stage = sobj
         rs.sequence = sequence
         rs.save()
         
         # Increment sequence of stage
         sequence += 100
Ejemplo n.º 4
0
def main():
    rds = json.load(open('routes_detail.json', 'r'))
    from routes.models import Route, RouteStage, ROUTE_TYPE_MAPPING
    from stages.models import Stage

    for r in Route.objects.filter(city=CITY):
        r.city = CITY + '_old'
        r.save()

    # For every route number in the dictionary
    for mtc_name in rds:
        display_name, slug = resolve_route_name(mtc_name)
        rd = rds[mtc_name]
        if rd["source"] is None or rd["destination"] is None or len(
                rd["stages"]) == 0:
            #print "Route %s skipped (Reason: Incomplete)" % mtc_name
            continue  # Skipping Incomplete routes
        service_type = rd["service_type"]
        s_type = MTC_TYPE_REVERSE_MAP[service_type]

        # if the route is present already, edit it
        if not Route.objects.filter(city=CITY).filter(slug=slug):
            r = Route()
        else:
            r = Route.objects.filter(city=CITY).get(slug=slug)

        # Add/Reset details of the route
        r.display_name = display_name
        r.city = CITY
        r.mtc_name = mtc_name
        if r.types is None or r.types == "":
            r.types = s_type
        elif s_type not in r.types.split(','):
            r.types = r.types + "," + s_type
        r.fare = -1  #TODO: Remove fare data
        r.time = -1  #TODO: Remove time data
        r.slug = slugify(slug)

        # Add new/existing stage object as route's start stage
        sstage = rd["source"]
        try:
            ssobj = Stage.objects.get(city=CITY, mtc_name=sstage)
        except Stage.DoesNotExist:
            ssobj = Stage()
            ssobj.display_name = sstage.title()
            ssobj.city = CITY
            ssobj.mtc_name = sstage
            ssobj.save()
        r.start = ssobj

        # Add new/existing stage object as route's end stage
        estage = rd["destination"]
        try:
            esobj = Stage.objects.get(city=CITY, mtc_name=estage)
        except Stage.DoesNotExist:
            esobj = Stage()
            esobj.display_name = estage.title()
            esobj.city = CITY
            esobj.mtc_name = estage
            esobj.save()
        r.end = esobj

        # Save the route
        r.save()

        # Add RouteStage object for every stage in route
        sequence = 100
        for stage in rd["stages"]:

            # Get or create stage object
            try:
                sobj = Stage.objects.get(city=CITY, mtc_name=stage)
            except Stage.DoesNotExist:
                sobj = Stage()
                sobj.display_name = stage.title()
                sobj.city = CITY
                sobj.mtc_name = stage
                sobj.save()

            # Get or create RouteStage object
            try:
                rs = RouteStage.objects.filter(route=r).get(stage=sobj)
            except RouteStage.DoesNotExist:
                rs = RouteStage()
            rs.route = r
            rs.stage = sobj
            rs.sequence = sequence
            rs.save()

            # Increment sequence of stage
            sequence += 100