python - 当它应该持续循环时,for循环不起作用
问题描述
async def helper():
a = "SELECT username FROM stoccssss"
cursor.execute(a)
people = cursor.fetchall()
for x in people:
cursor.execute("SELECT stock_selected FROM stoccssss WHERE username=%s", (x))
thingy = cursor.fetchall()
balls = ' '.join(map(str, thingy))
stockthingy = str(balls).replace('[', '')
stockthingy1 = str(stockthingy).replace(']', '')
stockthingy2 = str(stockthingy1).replace('(', '')
stockthingy3 = str(stockthingy2).replace(')', '')
stockthingy4 = str(stockthingy3).replace("'", '')
stockthingy5 = str(stockthingy4).replace(",", "")
stockTicker = yf.Ticker(stockthingy5.upper())
hmm = stockTicker.history(period='5m')
hmm = hmm.reset_index()
test = str(hmm['High']).split()
price = str(test[1])
cursor.execute("SELECT money_amount FROM stoccssss WHERE username=%s", (x))
moneycap = cursor.fetchone()
moneycap = str(moneycap).replace('(', '')
moneycap = str(moneycap).replace(')', '')
moneycap = str(moneycap).replace(',', '')
if moneycap < price:
cursor.execute("SELECT username FROM stoccssss WHERE username=%s", (x))
user = cursor.fetchone()
user = str(user).replace('(', '')
user = str(user).replace(')', '')
user = str(user).replace(',', '')
user = str(user).replace("'", '')
user = client.get_user(int(user))
await user.send("YOUR STOCK HAS SURPASSED YOUR PRICE OF " + str(moneycap) + " POG")
return
else:
cursor.execute("SELECT username FROM stoccssss WHERE username=%s", (x))
user = cursor.fetchone()
user = str(user).replace('(', '')
user = str(user).replace(')', '')
user = str(user).replace(',', '')
user = str(user).replace("'", '')
user = client.get_user(int(user))
await user.send("YOUR STOCK HAS GONE LOWER THAN YOUR PRICE OF " + str(moneycap) + " POG")
return
await asyncio.sleep(5)
@client.event
async def on_ready():
print("running")
await helper()
该代码旨在在股票高于或低于某个价格时向某人发送消息,但由于某种原因,该代码只运行一次,再也不会运行
有谁知道这里发生了什么?
在此处添加文本,因为它要求我提供更多详细信息,但我不知道还能说什么,因此请忽略最后一行文本
是的,代码缩进正确,stackoverflow搞砸了
解决方案
你没有把 helper() 放在一个循环中,只是在做
while True:
helper()
应该做的伎俩。
推荐阅读
- django - 在 Django dev、localhost 环境中测试 500.html
- sql - 如何在 SQL 中高效地使用多表连接查询?
- ruby - 无法找出 ruby 数学错误。建议?
- java - 如何在 Spring Boot REST API 中启用对 JSON / Jackson @RequestBody 的严格验证?
- python - 使用 get-pip 在 OSX 上安装时找不到 Pip 命令
- javascript - 如何从这个嵌套数组中获取价值
- python - 类变量根据它们的类型表现不同(共享或不共享)
- python - Python BaseHTTPRequestHandler 服务器仅适用于第一个 GET 请求
- javascript - 无法在 Localhost 上启动 tui-image-editor
- firebase - 使用 Cloud run 而不是 Cloud Functions 会受益吗?它在 GCP 中的什么位置?