刚刚开始学习Python,所以我可以制作Reddit机器人并遇到麻烦。我得到的行“模块对象不可调用”:
bitcoin_price = base().get_current_price()
来自此代码:
import praw
import config
import time
import os
import requests
from exchanges import base
def bot_login():
print("Logging in...")
r = praw.Reddit(username = config.username,
password = config.password,
client_id = config.client_id,
client_secret = config.client_secret,
user_agent = "ZaRollaCodsta's bitcoin bot")
print("logged in!")
return r
def run_bot(r, comments_replied_to):
for comment in r.subreddit('test').comments(limit=25):
if "bitcoin" in comment.body:
print("Found comment containing \"bitcoin\".")
comment_reply = "Did I hear bitcoin?\nHere is the price:\n\n"
bitcoin_price = base().get_current_price()
comment_reply += ">" + bitcoin_price + "\n\nTo the moon!"
comment.reply(comment_reply)
print("Replied to comment " + comment.id)
comments_replied_to.append(comment.id)
with open ("comments_replied_to.txt", "a") as f:
f.write(comment.id + "\n")
print("Sleeping for 10 seconds...")
#Sleep for 10 seconds...
time.sleep(10)
def get_saved_comments():
if not os.path.isfile("comments_replied_to.txt"):
comments_replied_to = []
else:
with open("comments_replied_to.txt", "r") as f:
comments_replied_to = f.read()
comments_replied_to = comments_replied_to.split("\n")
return comments_replied_to
r = bot_login()
comments_replied_to = get_saved_comments()
while True:
run_bot(r, comments_replied_to)
我已经尝试了Stack Overflow上的所有解决方案,但似乎都没有。