Exemple #1
0
def test_no_station():
    import pwaqi

    station = 1
    res = pwaqi.get_station_observation(station, 'demo')

    assert res['idx'] == 1437
Exemple #2
0
def wrong_token_test_observations():
    import pwaqi

    station = 1437
    res = pwaqi.get_station_observation(station, 'asjkfdhasjk')

    assert res['status'] == "error"
Exemple #3
0
def test_observations():
    import pwaqi

    station = 1437
    res = pwaqi.get_station_observation(station, 'demo')

    assert 'city' in res
    assert station == res['idx']
Exemple #4
0
 def update(self):
     """Get the data from World Air Quality Index and updates the states."""
     import pwaqi
     try:
         self.data = pwaqi.get_station_observation(self._station_id,
                                                   self._token)
     except AttributeError:
         _LOGGER.exception("Unable to fetch data from WAQI")
Exemple #5
0
def collect_station_pollution_data(
        station_id, token='09f4aebf96d26720c88d48f23293f18a6e912eb4'):
    print('Collecting pollution data for station {} ...'.format(station_id))
    return pw.get_station_observation(station_id, token)
        if x['p'] == 'so2':
            valso2 = x['v']
            continue
        if x['p'] == 't':
            valt = x['v']
            continue
    return [
        valcity, valaqi, valtime, valco, valh, valno2, valpm10, valpm25,
        valso2, valt
    ]


token = "8a44be330249ff56edb42808dae9a7f12278bd5c"
file_obj = open("C:\\Users\\Prateek\\aqi_data.csv", "a")

delcd = pwaqi.findStationCodesByCity('delhi', token)[0]
bancd = pwaqi.findStationCodesByCity('bangalore', token)[0]
delobs = pwaqi.get_station_observation(delcd, token)
banobs = pwaqi.get_station_observation(bancd, token)
delrow = createRowItem(delobs)
banrow = createRowItem(banobs)

file_obj.write("\n'" + str(delrow[0]) + "'," + str(delrow[1]) + "," +
               str(delrow[2]) + "," + str(delrow[3]) + "," + str(delrow[4]) +
               "," + str(delrow[5]) + "," + str(delrow[6]) + "," +
               str(delrow[7]) + "," + str(delrow[8]) + "," + str(delrow[9]))
file_obj.write("\n'" + str(banrow[0]) + "'," + str(banrow[1]) + "," +
               str(banrow[2]) + "," + str(banrow[3]) + "," + str(banrow[4]) +
               "," + str(banrow[5]) + "," + str(banrow[6]) + "," +
               str(banrow[7]) + "," + str(banrow[8]) + "," + str(banrow[9]))