Exemplo n.º 1
0
 async def _check_existing(stop):
     epoch = datetime.datetime(1970, 1, 1)
     day_start = datetime.datetime.utcnow().replace(hour=6,
                                                    minute=0,
                                                    second=0,
                                                    microsecond=0)
     day_end = datetime.datetime.utcnow().replace(hour=22,
                                                  minute=0,
                                                  second=0,
                                                  microsecond=0)
     day_start = (day_start - epoch).total_seconds()
     day_end = (day_end - epoch).total_seconds()
     result = (TrainerReportRelation.select(
         TrainerReportRelation.id, TrainerReportRelation.created,
         LocationTable.id.alias('location_id'),
         LocationTable.name.alias('location_name'),
         HideoutTable.rocket_leader.alias('leader'),
         HideoutTable.first_pokemon, HideoutTable.second_pokemon,
         HideoutTable.third_pokemon, LocationTable.latitude,
         LocationTable.longitude, TrainerReportRelation.message,
         TrainerReportRelation.trainer).join(
             LocationTable,
             on=(TrainerReportRelation.location_id == LocationTable.id)
         ).join(
             LocationRegionRelation,
             on=(LocationTable.id == LocationRegionRelation.location_id)
         ).join(
             RegionTable,
             on=(RegionTable.id == LocationRegionRelation.region_id)).join(
                 HideoutTable,
                 on=(TrainerReportRelation.id ==
                     HideoutTable.trainer_report_id)).
               where((LocationTable.name == stop.name)
                     & (TrainerReportRelation.created > day_start)
                     & (TrainerReportRelation.created < day_end)
                     & (TrainerReportRelation.cancelled == False)).order_by(
                         TrainerReportRelation.created))
     results = result.objects(HideoutInstance)
     if len(results) > 0:
         return result.objects(HideoutInstance)[0]
     return None
Exemplo n.º 2
0
 def get_single_hideout(report_id):
     result = (TrainerReportRelation.select(
         TrainerReportRelation.id, TrainerReportRelation.created,
         LocationTable.id.alias('location_id'),
         LocationTable.name.alias('location_name'),
         HideoutTable.rocket_leader.alias('leader'),
         HideoutTable.first_pokemon, HideoutTable.second_pokemon,
         HideoutTable.third_pokemon, LocationTable.latitude,
         LocationTable.longitude, TrainerReportRelation.message,
         TrainerReportRelation.trainer).join(
             LocationTable,
             on=(TrainerReportRelation.location_id == LocationTable.id)
         ).join(
             LocationRegionRelation,
             on=(LocationTable.id == LocationRegionRelation.location_id)
         ).join(
             RegionTable,
             on=(RegionTable.id == LocationRegionRelation.region_id)).join(
                 HideoutTable,
                 on=(TrainerReportRelation.id ==
                     HideoutTable.trainer_report_id)).where(
                         TrainerReportRelation.id == report_id))
     return result.objects(HideoutInstance)[0]