I'm trying to make a simple python script since i've never done anything in python!
Soo what i have: Script will get Data from my API and displays it on my linux bar, the except will print a message when the data wont come from API, for example when there is no internet connection!
What i'm looking for: currently my API returns 2 values as you can see (sectionName, webTitle), these are text properties which i'm printing to the bar, i want to add a new property link = data['response']['results'][0]["link"]
which will contain a link, the question is that i don't want to print the link, i want to open the link on a Key_pressing! How can i achieve this?
#!/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!')
You can use
keyboard.add_hotkey(hotkey, callback, args=(), suppress=False, timeout=1, trigger_on_release=False)
function in keyboard library to invoke a callback when you press the hotkey.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.