1

While working with json in python, I've written this small script to fetch the current price of BTC. This works fine when I run the script in Ubuntu terminal.

What I want is to update the variable current_price for every minute so that I can use this variable to display a desktop notification for current price.

I was looking for cron to schedule the task but It'll not work because I want to run the script after each minute, not at a specific time.

what is the best practice to achieve this?

import urllib, json

url = "https://koinex.in/api/ticker"
response = urllib.urlopen(url)
data = json.loads(response.read())

current_price = data["prices"]["BTC"]

print current_price 
  • You can set up `cron` to run every minute: https://stackoverflow.com/questions/5398014/using-crontab-to-execute-script-every-minute-and-another-every-24-hours – r.ook Jan 24 '18 at 07:17

1 Answers1

0

To run the script every minute you can use cron job:

EX:

* * * * * python /PATH_TO_SCRIPT/script.py
Rakesh
  • 81,458
  • 17
  • 76
  • 113