I would like to make a python code that will:
Read data from api and refresh every 10 minutеs.
Display this data on LCD display in two sheets which change continuously every 5 seconds
I do not know how to make one part of the code run independently of the other. In my case.. - BLOCK1 run every 300s - BLOCK2 run nonstop
Here is my Python code... of course, it's not working and is not finished yet. Thank you for your help!
from urllib import urlopen
import I2C_LCD_driver1
import json
import time
mylcd = I2C_LCD_driver1.lcd()
while True:
# BLOCK 1 - start every 600s
CNV7 = urlopen('https://www.coincalculators.io/api/allcoins.aspx?hashrate=12200&power=1400&powercost=0.15&difficultytime=0&algorithm=CryptoNightV7').read()
dataCNV7= json.loads(CNV7)
coinCNV7 = dataCNV7[0]["name"]
algoCNV7 = dataCNV7[0]["algorithm"]
dayUSDCNV7 = dataCNV7[0]["profitInDayUSD"]
print ("Algoritm:"),algoCNV7
print ("Coin:"),coinCNV7
dayUSDCNV7 = float(dayUSDCNV7)
dayEUCNV7 = dayUSDCNV7*0.88
print("%.2f" % dayEUCNV7),("Eu/dan")
time.sleep(600) # Read API every 10minuts
# BLOCK 2 - must run non-stop
if dayEUCNV7 > 3:
while True:
print("RELEY ON")
mylcd.lcd_clear()
mylcd.lcd_display_string("RELEY - ON",1,0)
mylcd.lcd_display_string("Profit:",2,0)
mylcd.lcd_display_string(str(dayEUCNV7),3,2)
print ("LCD page 1")
time.sleep(2)
mylcd.lcd_clear()
mylcd.lcd_display_string("RELEY- ON",1,0)
mylcd.lcd_display_string(str(coinCNV7),3,2)
print ("LCD page 2")
time.sleep(2)
else:
while True:
print("RELEY OFF")
mylcd.lcd_clear()
mylcd.lcd_display_string("RELEY - OFF",1,0)
mylcd.lcd_display_string("Profit:",2,0)
mylcd.lcd_display_string(str(dayEUCNV7),3,2)
print ("LCD page 1")
time.sleep(2)
mylcd.lcd_clear()
mylcd.lcd_display_string("RELEY- OFF",1,0)
mylcd.lcd_display_string(str(coinCNV7),3,2)
print ("LCD page 2")
time.sleep(2)