Пример #1
0
 def downloadDbCoords(self):
     try:
         connection = mysql.connector.connect(host=self.host,
                                              user=self.user, port=self.port, passwd=self.password,
                                              db=self.database)
     except:
         log.error("Could not connect to the SQL database")
         return False
     from geofenceHelper import GeofenceHelper
     log.info('Downloading coords')
     lll = args.latlngleft
     llr = args.latlngright
     queryStr = ""
     if lll and llr:
         queryStr = ' where (latitude BETWEEN {} AND {}) AND (longitude BETWEEN {} AND {}) and latitude IS NOT NULL and longitude IS NOT NULL'.format(lll[0], llr[0],
                                                                                                   lll[1], llr[1])
     else:
         queryStr = ' where latitude IS NOT NULL and longitude IS NOT NULL'
     query = "SELECT latitude, longitude FROM gym {}".format(queryStr)
     cursor = connection.cursor()
     cursor.execute(query)
     file = open(args.file, 'w')
     listOfCoords = []
     for (lat, lon) in cursor:
         # file.write(str(lat) + ', ' + str(lon) + '\n')
         listOfCoords.append([lat, lon])
     cursor.close()
     connection.close()
     geofenceHelper = GeofenceHelper()
     geofencedCoords = geofenceHelper.get_geofenced_coordinates(listOfCoords)
     for (lat, lon) in geofencedCoords:
         file.write(str(lat) + ', ' + str(lon) + '\n')
     file.close()
     log.info('Downloading finished.')
     return True
Пример #2
0
    def getNextRaidHatches(self, delayAfterHatch):
        try:
            connection = mysql.connector.connect(host=self.host,
                                                 user=self.user,
                                                 port=self.port,
                                                 passwd=self.password,
                                                 db=self.database)
        except:
            log.error("Could not connect to the SQL database")
            return []
        cursor = connection.cursor()
        # query = (' SELECT start, latitude, longitude FROM raid LEFT JOIN gym ' +
        #    'ON raid.gym_id = gym.gym_id WHERE raid.start >= \'%s\''
        #    % str(datetime.datetime.now() - datetime.timedelta(hours = self.timezone)))
        dbTimeToCheck = datetime.datetime.now() - datetime.timedelta(
            hours=self.timezone)

        query = (
            ' SELECT start, latitude, longitude FROM raid LEFT JOIN gym ' +
            'ON raid.gym_id = gym.gym_id WHERE raid.end > \'%s\' ' %
            str(dbTimeToCheck) + 'AND raid.pokemon_id IS NULL')
        # print(query)
        # data = (datetime.datetime.now())
        cursor.execute(query)
        from geofenceHelper import GeofenceHelper
        geofenceHelper = GeofenceHelper()
        data = []
        log.debug("Result of raidQ query: %s" % str(query))
        for (start, latitude, longitude) in cursor:
            if latitude is None or longitude is None:
                log.warning("lat or lng is none")
                continue
            elif not geofenceHelper.is_coord_inside_include_geofence(
                [latitude, longitude]):
                log.debug(
                    "Excluded hatch at %s, %s since the coordinate is not inside the given include fences"
                    % (str(latitude), str(longitude)))
                continue
            timestamp = self.dbTimeStringToUnixTimestamp(str(start))
            data.append((timestamp + delayAfterHatch * 60,
                         RaidLocation(latitude, longitude)))

        log.debug("Latest Q: %s" % str(data))
        connection.commit()
        cursor.close()
        connection.close()
        return data