Closed herbetom closed 3 years ago
Ah, I get it -.-'
TypeError: float() argument must be a string or a number, not 'NoneType'
yeah, i would appreciate a saver and non error throwing suggestion for the conversion
Otherwise this should be okay.
What default values would you like self.longitude
and self.latitude
to have?
None
?
The Node should have no location if nothing is configured (like it is currently with mesh-announce or gluon Nodes). I don't know about the best approach to get to this result.
I'd go with either
try:
self.longitude = float(parser.get(name, 'Longitude', fallback=None))
except TypeError:
self.longitude = None
try:
self.latitude = float(parser.get(name, 'Latitude', fallback=None))
except TypeError:
self.latitude = None
Which follows your default in your example config; https://github.com/Freifunk-Rhein-Neckar/mesh-announce/blob/d0739c1b1f614e98f8c03512cd7d96c031017898/respondd.conf.example#L33 https://github.com/Freifunk-Rhein-Neckar/mesh-announce/blob/d0739c1b1f614e98f8c03512cd7d96c031017898/respondd.conf.example#L36
Or this:
try:
self.longitude = float(parser.get(name, 'Longitude', fallback=None))
except TypeError:
pass
try:
self.latitude = float(parser.get(name, 'Latitude', fallback=None))
except TypeError:
pass
Which I understood is the behavior described in your last comment? Gotta go for today, thanks so far!
I choose the first approach. The other didn't work (or had much noise about the missing Var).
@TobleMiner What do you think? Could this be merged?
Tested without the last force push; broken, if no coordinates were provided. Tested with latest FP, works very well without them.
sn07 now runs with both #64 and #63 merged into master.
~eg. https://hannover.freifunk.net/karte/#/en/map/88e640ba7014~
~Without the hostname config parameter working it would identify as h2879555.stratoserver.net.~
edit: Testing is done, reverted back to master.
One possible enhancemnt I just came across is configparsers getfloat
method:
https://docs.python.org/3/library/configparser.html#configparser.ConfigParser.getfloat
I did another Force Push to implement it with the getfloat
method mentioned by @AiyionPrime
I like that approach much more then catching exceptions and it seems to do exactly what is needed. :+1:
The following things can now be controlled domain specific:
Hostname, Hardware-Model, Contact Information, VPN, Latitude and Longitude
resolves #65