在Debian中的启动应用程序中(可能还有其他基于debian和ubuntu的发行版)。有一个名为Geo线索演示代理的库,具有路径的实际库是
/usr/libexec/geoclue-2.0/demos/agent这是地理线索-2.0 https://gitlab.freedesktop.org/geoclue/geoclue/wikis/home的一部分。
到目前为止,我所知道的唯一问题是删除应用程序/服务。参见从… unix.stackexchange.com的问题。
我会发现它更有趣,如果我能够理解它显示了什么和它如何显示它。这篇关于人类地理线索的文章并不是针对普通用户的。
有人能帮我吗?我正在查看一些简单的线路,比如curl wttr.in/$location,您可以得到该位置的天气输出。一些互动的东西--很可能是,--只需要弄清楚怎么做。
发布于 2021-04-08 13:11:42
关于堆栈溢出,我发现了问题:我如何在Python中获得地理线索地理位置?
安装模块后使用GeoGlue
apt install gir1.2-geoclue-2.0我在python中创建了脚本geolocation.py
#!/usr/bin/env python
import gi
gi.require_version('Geoclue', '2.0')
from gi.repository import Geoclue
clue = Geoclue.Simple.new_sync('something', Geoclue.AccuracyLevel.NEIGHBORHOOD, None)
location = clue.get_location()
latitude = location.get_property('latitude')
longitude = location.get_property('longitude')
print('{},{}'.format(latitude, longitude))它给出了latitude,longtiture在bash中的应用
python getlocation.py我可以直接和wttr.in一起使用
curl wttr.in/$(python getlocation.py)如果设置属性executable
chmod u+x geolocation.py然后我甚至可以在没有python的情况下运行它-它将使用来自shebang (#!/usr/bin/env python)的值。
我甚至可以删除扩展.py并保留名称geolocation,然后它看起来就像
curl wttr.in/$(getlocation)(它必须在$( )中才能作为分离的进程执行)
我还可以直接使用python从服务器获取值。
#!/usr/bin/env python
import gi
gi.require_version('Geoclue', '2.0')
from gi.repository import Geoclue
clue = Geoclue.Simple.new_sync('something', Geoclue.AccuracyLevel.NEIGHBORHOOD, None)
location = clue.get_location()
latitude = location.get_property('latitude')
longitude = location.get_property('longitude')
#print('latitude :', latitude)
#print('longitude:', longitude)
import requests
url = 'https://wttr.in/{},{}'.format(latitude, longitude)
# to get it as HTML instead of TEXT (see PLAIN_TEXT_AGENTS in https://github.com/chubin/wttr.in/blob/master/lib/globals.py#L75)
#response = requests.get(url, headers={'User-Agent': ''}) #{'User-Agent': 'Mozilla/5.0'}
response = requests.get(url)
print(response.text)如果我在url末尾添加?format=j1
https://wttr.in/{},{}?format=j1然后,我将它作为JSON,可以在python中转换为dictionary,并以不同的方式格式化数据。
在Linix Mint 20,Python 3.8,Python 2.7上测试
By方式:
wttr.in似乎使用了运行在终端上的程序瓦戈。
geoclue似乎使用不同的方法来识别位置,但在我的情况下,它可能使用IP来识别它--但是我的Internet Provider可以每24小时改变我的IP,这个IP可以被不同地方的用户使用,所以有时它会给出错误的位置。在这一刻,它给我的位置,几乎30公里,我的地方-和后来的wttr.in给不同的天气。
有些web服务器使用GeoIP来自MaxMind将IP转换为位置--但当用户IP每隔几个小时更改一次时,也会遇到同样的问题。我记得,HTTP请求可以使用它,也可以下载带有信息的数据库,并在本地使用(但您必须不时更新数据库)
https://unix.stackexchange.com/questions/580711
复制相似问题