首先发布在这里!
我知道像这样的线程很少,我已经读过它们,但没有成功。
在True循环(在代码底部"中断"是)时可以突破并继续声音文件。我是编程的新手,只是在学习......
提前致谢。
# calculating coin price
coinprice = Decimal(binance()) * Decimal(binancecr())
shorted = round(coinprice, 4)
# creating list
highestvalue = [0.0001]
# getting current time
formattime = "%H:%M:%S"
now_utc = datetime.now(timezone('UTC'))
now_currenttime = now_utc.astimezone(timezone('Europe/Berlin'))
# getting current price
print(shorted, "$", "= Starting Price", "(", now_currenttime.strftime(formattime), ")")
while True:
# getting current time
formattime = "%H:%M:%S"
now_utc = datetime.now(timezone('UTC'))
now_currenttime = now_utc.astimezone(timezone('Europe/Berlin'))
# formatting coin price
deciplaces = Decimal(binance()) * Decimal(binancecr())
rounded = round(deciplaces, 4)
# getting highest price
for item in highestvalue:
if item < rounded:
del highestvalue[0]
highestvalue.append(rounded)
# printing highest price
print(highestvalue[0], "$", "= Highest Price ", "(", now_currenttime.strftime(formattime), ")")
# calculating desired price
percentage = Decimal(highestvalue[0]) * Decimal(0.001) / Decimal(100)
percentcalc = Decimal(highestvalue[0]) - Decimal(percentage)
percconv = Decimal(percentcalc)
percround = round(percconv, 4)
# calculating percentage change
change_percent = ((Decimal(highestvalue[0]) - Decimal(rounded)) / Decimal(rounded)) * Decimal(100.00)
convchange_percent = Decimal(change_percent)
roundchange_percent = round(convchange_percent, 4)
# printing current price, desired price and percentage changes
print(rounded, "$", "= Current Price ", "(", now_currenttime.strftime(formattime), ")")
print(percround, "$", "= Desired Price ", "(", now_currenttime.strftime(formattime), ")")
print(roundchange_percent, " %", "= Percent Change", "(", now_currenttime.strftime(formattime), ")")
print("--------------------------------------")
# checking price drop
if highestvalue[0] <= percround:
# when highestvalue[0] goes below percround while True won't break and continue to a sound file
break
# time interval in seconds
time.sleep(3)
# playing sound when coin price reaches desired price
winsound.PlaySound(fname, winsound.SND_FILENAME)