Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stations API: send measurements #272

Closed
csparpa opened this issue Nov 5, 2018 · 5 comments
Closed

Stations API: send measurements #272

csparpa opened this issue Nov 5, 2018 · 5 comments
Assignees
Labels

Comments

@csparpa
Copy link
Owner

csparpa commented Nov 5, 2018

User Patrick Casbon reports errors when sending measurements to the Stations API:

timestamp = last_hour_end + timedelta(microseconds=1)
print (timestamp)
unixtime = int(time.mktime(timestamp.timetuple()))
print(unixtime)
print (type(unixtime))
raw_measurement_obj =  pyowm.stationsapi30.measurement.Measurement(station_id, unixtime,
   temperature=temp)
print (raw_measurement_obj)
mgr.send_measurement(raw_measurement_obj)

# output

2018-11-04 14:00:00
1541340000
<class 'int'>
<pyowm.stationsapi30.measurement.Measurement - station_id=5bdda367199f0300011f2b11, created_at=1541340000>
Traceback (most recent call last):
 File "/home/pi/Makerlife-Project3-Weatherstation-master/SendToOWM.py", line 50, in <module>
   mgr.send_measurement(raw_measurement_obj)
 File "/home/pi/.local/lib/python3.5/site-packages/pyowm/stationsapi30/stations_manager.py", line 153, in send_measurement
   headers={'Content-Type': 'application/json'})
 File "/home/pi/.local/lib/python3.5/site-packages/pyowm/commons/http_client.py", line 59, in post
   HttpClient.check_status_code(resp.status_code, resp.text)
 File "/home/pi/.local/lib/python3.5/site-packages/pyowm/commons/http_client.py", line 108, in check_status_code
   raise api_call_error.APICallError(payload)
pyowm.exceptions.api_call_error.APICallError: Exception in calling OWM web API.
Reason: {"code":400001,"message":"DT must be greater than zero"}
Caused by: None

The issue might be related to line:

def to_dict(self):

This method is not dumping the Measurement object in the right way and therefore a wrong JSON is actually sent to the Openweathermap API

@csparpa csparpa added the bug label Nov 5, 2018
@csparpa csparpa added this to the Release 2.10.0 milestone Nov 5, 2018
@csparpa csparpa self-assigned this Nov 5, 2018
csparpa added a commit that referenced this issue Nov 6, 2018
@csparpa
Copy link
Owner Author

csparpa commented Nov 6, 2018

Hi @patcas this commit 632764a should fix the issue.. please can you test it out?
Thanks

@patcas
Copy link

patcas commented Nov 7, 2018

Hi @csparpa very many thanks for that! I have tried to test but I'm afraid that my git expertise probably isn't good enough. What I did was:
git clone https://github.com/csparpa/pyowm.git cd pyowm git checkout 632764a sudo python3 setup.py install

Then I ran my Python code from the Thonny IDE. But with no difference in the output -- even the code line numbers!
What have I done wrong? Any help gratefully received!

@csparpa
Copy link
Owner Author

csparpa commented Nov 7, 2018

What I would do then is avoid using the IDE (let's tear off one layer of complexity) and test patch from a "quick" command line script

As far as the installation is concerned, did you remove the previous pyowm installation before performing the setup actions you that reported? Just go with: sudo pip uninstall pyowm and then re-execute your commands

... or, alternatively, you can choose not to python3 setup.py install the library and just import the library from the script, which you need then to put eg. inside the pyowm root folder

Please let me know!

@patcas
Copy link

patcas commented Nov 8, 2018

Success! Very many thanks, indeed, @csparpa !
I hadn't removed the previous pyowm, so I didsudo pip3 uninstall pyowm and that appeared to work. But running my code produced the previous error. I looked in /home/pi/.local/lib/python3.5/site-packages/pyowm and there still seemed to be a lot of files in there.
Anyway, I copied my code into /home/pi/pyowm (the directory I had cloned the package to. Ran it from there and it was great:
`2018-11-08 20:00:00
2018-11-08 20:59:59
SELECT AVG(AMBIENT_TEMPERATURE) FROM WEATHER_MEASUREMENT WHERE CREATED BETWEEN '2018-11-08 20:00:00' AND '2018-11-08 20:59:59.999999'
6.317531
2018-11-08 21:00:00
1541710800
<class 'int'>

<pyowm.stationsapi30.measurement.Measurement - station_id=5bdda367199f0300011f2b11, created_at=1541710800>
`
So, many thanks again, much appreciated!
My next task is to get the other measurements working and then upload on a regular basis...

@csparpa
Copy link
Owner Author

csparpa commented Nov 9, 2018

well done! thanks for testing it. and, by the way, I've added your GitHub handle to the CONTRIBUTORS.md file!

@csparpa csparpa closed this as completed Nov 13, 2018
csparpa added a commit that referenced this issue Dec 21, 2018
* No more Py2.7 and Py3.3

* Remove references to Python <= 3.3. Fixes #252

* Removed support for Python 2. Fixes #243

* These should have been removed far before

* Updated with all refatored subpackages and their non-code includes

* Fixes #263

* Fixes #258

* Improve docs

* even better, with a logo!

* Fixes #269

* #269

* skeleton for tile client

* even better, with a logo!

* now also providing weather icon URLs

* fix upper version boundary and fix keywords

* Refactored out to a separate URI files

* forgot to commit

* Fetch a PNG file, with tests

* name inconsistencies make me *angry*...

* an image

* Tile entity

* Lots of mods... tiles now working!

* docs

* New property

* Small refactoring

* Add buy me a cofee page link

* Far better now

* Superb

* Fix broken URL

* a very first draft, testing how Travis behaves

* attempt 2

* attempt 3 (typo in yaml)

* attempt 3

* attempt 4

* attempt 5

* Travis does not support Py37 yet. Furthermore, already existing wheels and sdists broke the build

* test 1

* test 2 (trying to make it more clever)

* test 3

* test 4

* test 5

* test 6

* test 6

* test 6

* test 8

* test 8

* Fixing #271

* now tagging development releases on TestPyPI (attempt 1)

* attempt 2 (various fixes)

* attempt 3 (skipping some build steps if on the develop branch)

* attempt 4

* attempt 5

* attempt 6

* attempt 7

* more badges

* attempt 8

* attempt 9

* tox with coverage and fix timestamp issues in concurrent deploys

* This should fix #272

* update

* oh s**t I forgot..

* Removing lib dependecies duplication (now setup.py reads deps from requirements.txt)

* better now

* absolute paths! always!!!

* OK so.. no requirements.txt anymore.

* let's do it anyway

* Safe to remove?

* Improvement

* Safe to remove?

* Agro API: Polygons API subset + docs

* Agro API: Polygons API subset + docs

* __repr__ and docs

* Soil entity with tests; fixes to imports/docs

* Finalizes #245

* Seeds for Imagery API subset of Agro API; fix docs missing

* repr everywhere

* Refactoring

* Moved Tile class into commons; Imagery module now provides the class hierarchy for dealing with Satellite Imagery Search operation

* Fetching a GeoTIF image and some refactoring

* more tests and btter docs; finalized download_satellite_image

* Implement stats retrieval for satellite images

* Refactored enum

* Refactoring

* Implemented search and download methods for satellite imagery; also some integration tests; lots of refactoring

* More integrations tests

* Refactoring and more unit tests. Completed satellite imagery related features

* Name refactoring

* One more method and test

* Fix docs

* dump to version 2.10

* fix prints

* Update README.md

* change PyPI production URL

* fix duplicated tag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants