Ejemplo n.º 1
0
def main():
   sjs = json.load(open('stages.json', 'r'))
   from stages.models import Stage
   
   for s in Stage.objects.filter(city=CITY):
      s.city = CITY + '_old'
      s.save()

   # For every stage name in the list
   for sj in sjs:
      try:
         s = Stage.objects.get(city__contains=CITY, mtc_name = sj)
         s_old = Stage()
         s_old.display_name = s.display_name
         s_old.city = s.city
         s_old.mtc_name = s.mtc_name
         s_old.save()
      except Stage.DoesNotExist:
         s = Stage()
      s.display_name = sj.title()
      s.city = CITY
      s.mtc_name = sj
      # Save the stage
      s.save()
Ejemplo n.º 2
0
def main():
    sjs = json.load(open('stages.json', 'r'))
    from stages.models import Stage

    # For every stage name in the list
    for sj in sjs:
        # if the stage is present already, do nothing
        if Stage.objects.filter(city='delhi').filter(mtc_name=sj):
            continue
        new_stage = Stage()
        new_stage.display_name = sj
        new_stage.city = 'delhi'
        new_stage.mtc_name = sj

        # Save the stage
        new_stage.save()
Ejemplo n.º 3
0
def main():
   sjs = json.load(open('stages.json', 'r'))
   from stages.models import Stage
   
   # For every stage name in the list
   for sj in sjs:
      # if the stage is present already, do nothing
      if Stage.objects.filter(city='delhi').filter(mtc_name=sj):
         continue
      new_stage = Stage()
      new_stage.display_name = sj
      new_stage.city = 'delhi'
      new_stage.mtc_name = sj
      
      # Save the stage
      new_stage.save()
Ejemplo n.º 4
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.º 5
0
    dest.save()
    for rl in src.routelinks.all():
        rl.stage = dest
        rl.save()

    for sr in src.start_for_routes.all():
        sr.start = dest
        sr.save()

    for er in src.end_for_routes.all():
        er.end = dest
        er.save()


from stages.models import Stage
if len(sys.argv) != 3:
    print "Usage: python %s <stageid1> <stageid2>" % sys.argv[0]

st1 = Stage.objects.get(id=int(sys.argv[1]))
st2 = Stage.objects.get(id=int(sys.argv[2]))

temp = Stage()
temp.display_name = 'Delete me'
temp.city = 'wonderland'
temp.save()

copy_stage(temp, st1)
copy_stage(st1, st2)
copy_stage(st2, temp)
temp.delete()
Ejemplo n.º 6
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.º 7
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.º 8
0
   dest.city = src.city
   dest.save()
   for rl in src.routelinks.all():
      rl.stage = dest
      rl.save()

   for sr in src.start_for_routes.all():
      sr.start = dest
      sr.save()

   for er in src.end_for_routes.all():
      er.end = dest
      er.save()

from stages.models import Stage
if len(sys.argv) != 3:
   print "Usage: python %s <stageid1> <stageid2>" % sys.argv[0]

st1 = Stage.objects.get(id=int(sys.argv[1]))
st2 = Stage.objects.get(id=int(sys.argv[2]))

temp = Stage()
temp.display_name = 'Delete me'
temp.city = 'wonderland'
temp.save()

copy_stage(temp, st1)
copy_stage(st1, st2)
copy_stage(st2, temp)
temp.delete()
Ejemplo n.º 9
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