Exemple #1
0
 def test_get_geoip_data_for_x_forwarded_for(self):
     with self.app.test_request_context(
             environ_base={'HTTP_X_FORWARDED_FOR': '1.2.3.4'}):
         simple_geoip = SimpleGeoIP(self.app)
         data = simple_geoip.get_geoip_data()
         self.assertIsInstance(data, dict)
         self.assertEqual(data['ip'], '1.2.3.4')
Exemple #2
0
 def test_get_geoip_data_with_multiple_proxies(self):
     with self.app.test_request_context(environ_base={
             'HTTP_X_FORWARDED_FOR':
             '1.2.3.4, 1.2.3.5, 1.2.3.6, 1.2.3.7'
     }):
         simple_geoip = SimpleGeoIP(self.app)
         data = simple_geoip.get_geoip_data()
         self.assertIsInstance(data, dict)
         self.assertEqual(data['ip'], '1.2.3.4')
Exemple #3
0
    def test_get_geoip_data_with_malformed_x_forwarded_for(self):
        environ_base = {
            'REMOTE_ADDR': '127.0.0.1',
            'HTTP_X_FORWARDED_FOR': '<script> alert(1) </script'
        }

        with self.app.test_request_context(environ_base=environ_base):
            simple_geoip = SimpleGeoIP(self.app)
            data = simple_geoip.get_geoip_data()
            self.assertIsInstance(data, dict)
            self.assertEqual(data['ip'], request.remote_addr)
Exemple #4
0
def get_forecast_data():
    session['sequence'] = 0
    seg = session.get('sequence')
    simple_geoip = SimpleGeoIP(current_app)
    geoip_data = simple_geoip.get_geoip_data()

    depart = 'Val-de-Marne'
    currentdate = datetime.today().strftime('%Y-%m-%d')
    last = datetime.strptime('2021-01-31', "%Y-%m-%d")
    d2 = datetime.strptime(datetime.today().strftime('%Y-%m-%d'), "%Y-%m-%d")
    days_current = abs((d2 - last).days)

    current_forecast = create_dates('2021-01-31', days_current)
    demain_forcast = create_dates('2021-01-31', (days_current + 1))
    seven_forcats = create_dates('2021-01-31', (days_current + 7))
    quinze_forcats = create_dates('2021-01-31', (days_current + 15))
    tente_forcats = create_dates('2021-01-31', (days_current + 30))
    for i in range(len(departments)):
        seven_days_svr = forecast_svr(x_test[i], days_current, model[i], 60,
                                      scaler[i])
        current_forecast[departments[i]] = np.array(seven_days_svr)
    for i in range(len(departments)):
        seven_days_svr = forecast_svr(x_test[i], days_current + 1, model[i],
                                      60, scaler[i])
        demain_forcast[departments[i]] = np.array(seven_days_svr)
    for i in range(len(departments)):
        seven_days_svr = forecast_svr(x_test[i], days_current + 7, model[i],
                                      60, scaler[i])
        seven_forcats[departments[i]] = np.array(seven_days_svr)
    for i in range(len(departments)):
        seven_days_svr = forecast_svr(x_test[i], days_current + 15, model[i],
                                      60, scaler[i])
        quinze_forcats[departments[i]] = np.array(seven_days_svr)
    for i in range(len(departments)):
        seven_days_svr = forecast_svr(x_test[i], days_current + 30, model[i],
                                      60, scaler[i])
        tente_forcats[departments[i]] = np.array(seven_days_svr)
    tente_forcats = tente_forcats.tail(30)
    quinze_forcats = quinze_forcats.tail(15)
    seven_forcats = seven_forcats.tail(7)
    demain_forcast = demain_forcast.tail(1)
    current_forecast = current_forecast.tail(1)
    print(current_forecast)
    #print(seven_forcats.tail(7))
    return {
        'current': current_forecast.to_json(),
        'tomorrow': demain_forcast.to_json(),
        'seven_days': seven_forcats.to_json(),
        'fifteen_days': quinze_forcats.to_json(),
        'thirty_days': tente_forcats.to_json()
    }
Exemple #5
0
 def test_get_geoip_data_for_custom_addr(self):
     with self.app.test_request_context():
         simple_geoip = SimpleGeoIP(self.app)
         data = simple_geoip.get_geoip_data('8.8.8.8')
         self.assertIsInstance(data, dict)
         self.assertEqual(data['ip'], '8.8.8.8')
Exemple #6
0
 def test_get_geoip_data(self):
     with self.app.test_request_context():
         simple_geoip = SimpleGeoIP(self.app)
         data = simple_geoip.get_geoip_data()
         self.assertIsInstance(data, dict)