def updateInsertWeather(self, lat, lng, weatherid, captureTime): now_timezone = datetime.datetime.fromtimestamp(float(captureTime)) now_timezone = time.mktime(now_timezone.timetuple()) - (self.timezone * 60 * 60) now = (datetime.datetime.fromtimestamp(float(captureTime)) - datetime.timedelta(hours=self.timezone)).strftime( "%Y-%m-%d %H:%M:%S") s2cellid = S2Helper.latLngToCellId(lat, lng) realLat, realLng = S2Helper.middleOfCell(s2cellid) 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 = ('INSERT INTO weather ' + '(s2_cell_id, latitude, longitude, cloud_level, rain_level, ' + 'wind_level, snow_level, fog_level, wind_direction, gameplay_weather, ' + 'severity, warn_weather, world_time, last_updated) VALUES ' + ' (' + str(s2cellid) + ', ' + str(lat) + ', ' + str(lng) + ', NULL, NULL, NULL, NULL, NULL, NULL, ' + '' + str(weatherid) + ', NULL, NULL, 1, \'' + str(now) + '\')' + ' ON DUPLICATE KEY UPDATE fog_level=0, cloud_level=0, snow_level=0, wind_direction=0, world_time=0, latitude=' + str(realLat) + ', longitude=' + str(realLng) + ', ' + ' gameplay_weather=' + str(weatherid) + ', last_updated=\'' + str(now) + '\'') cursor.execute(query) connection.commit() cursor.close() send_weather_webhook(s2cellid, weatherid, 0, 0, 2, now_timezone)
def updateInsertWeather(self, lat, lng, weatherid, captureTime): log.debug( 'updateInsertWeather: for {0}, {1} with WeatherId {2} at {3}'. format(lat, lng, weatherid, captureTime)) s2cellid = S2Helper.latLngToCellId(lat, lng) 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 = ( "INSERT INTO weather " + "(s2_cell_id, `condition`, alert_severity, warn, day, updated) " + "VALUES ({0}, {1}, {2}, {3}, {4}, {5}) " "ON DUPLICATE KEY UPDATE `condition`={1}, alert_severity={2}, warn = {3}, day={4}, updated={5}" .format(s2cellid, weatherid, 0, 0, 2, int(float(captureTime)))) cursor.execute(query) connection.commit() cursor.close() send_weather_webhook(s2cellid, weatherid, 0, 0, 2, float(captureTime))