Python 打开键绑定上的链接
我正在尝试制作一个简单的python脚本,因为我从来没有用python做过任何事情 看看我有什么: 脚本将从我的API获取数据,并将其显示在我的linux栏上, 当数据不来自API时,例如没有internet连接时,except将打印消息 我在找什么: 目前我的API返回2个值,如您所见(sectionName,webTitle), 这些是我正在打印到工具栏上的文本属性,我想添加一个新属性Python 打开键绑定上的链接,python,Python,我正在尝试制作一个简单的python脚本,因为我从来没有用python做过任何事情 看看我有什么: 脚本将从我的API获取数据,并将其显示在我的linux栏上, 当数据不来自API时,例如没有internet连接时,except将打印消息 我在找什么: 目前我的API返回2个值,如您所见(sectionName,webTitle), 这些是我正在打印到工具栏上的文本属性,我想添加一个新属性link=data['response']['results'][0][“link”],其中将包含一个链接,
link=data['response']['results'][0][“link”]
,其中将包含一个链接,问题是我不想打印链接,我想按一下键打开链接!我怎样才能做到这一点
#!/usr/bin/python
import requests
api_key = "API-KEY-HERE"
try:
data = requests.get("https://content.mysite.com/search?api-key="+api_key).json()
sectionName = data['response']['results'][0]["sectionName"]
webTitle = data['response']['results'][0]["webTitle"]
print(sectionName+': '+webTitle)
except requests.exceptions.RequestException as e: # This is the correct syntax
print ('Something went wrong!')
你可以用
keyboard.add_hotkey(hotkey, callback, args=(), suppress=False, timeout=1, trigger_on_release=False)
函数在按下热键时调用回调
您是只想在按下特定键时打开链接,还是想在按下任何键时打开链接?