为什么我有python错误unident不匹配任何外部缩进级别的错误


from TikTokApi import TikTokApi 
import time 
import os
import random 
api = TikTokApi()
def getLikeCount():
tiktoks = api.byUsername('user', count=1)
for tiktok in tiktoks:
likeCount = tiktok["stats"]["diggCount"]
shareCount = tiktok["stats"]["shareCount"]
commentCount = tiktok["stats"]["commentcount"]
followCount = tiktok["authorStats"]["followerCount"]
return (likeCount,shareCount,commentCount,followCount)
def fag():
os.system("afplay -/desktop/tiktok/fag.mp3 ")

def update():
initLikeCount = 0
while True:
results = getLikeCount()
currentNumLikes = results[0]
print("sleep time")
time.sleep(5)
if currentNumLikes > initLikeCount:
newLikes = currentNumLikes - initLikeCount
initLikeCount = currentNumLikes
print("new like count = ",newLikes)
for x in range(newLikes):
print("now playing this Fag.mp3",x)
time.sleep(random.randint(0,3))
fag()
else()
print("no new likes ):")
update()
#getLikeCount() 

为什么会发生这种情况?我正在制作一个tiktok机器人,每次我得到一个赞时,我都会有噪音播放(顺便说一句,我在ubuntu上,但这也发生在windows上(

else语句与if语句不对齐。

顺便说一句,下次使用ctrl-K在StackOverflow中对齐代码。

函数getLikeCountupdate中有几个小错误

def getLikeCount():
tiktoks = api.byUsername('user', count=1)
for tiktok in tiktoks:
likeCount = tiktok["stats"]["diggCount"]
shareCount = tiktok["stats"]["shareCount"]
commentCount = tiktok["stats"]["commentcount"]
followCount = tiktok["authorStats"]["followerCount"]
return (likeCount,shareCount,commentCount,followCount) # indentation corrected
def update():
initLikeCount = 0
while True:
results = getLikeCount()
currentNumLikes = results[0]
print("sleep time")
time.sleep(5)
if currentNumLikes > initLikeCount:
newLikes = currentNumLikes - initLikeCount
initLikeCount = currentNumLikes
print("new like count = ",newLikes)
for x in range(newLikes):
print("now playing this Fag.mp3",x)
time.sleep(random.randint(0,3))
fag()
#  else() <- your code
else: # indentation, brackets and colon corrected
print("no new likes ):")

相关内容

  • 没有找到相关文章

最新更新