Reputation: 21
Edit: This is why people new to Python should read books first... thanks for pointing out my really basic error, guys.
I have no idea what I'm doing so bear with me, here.
I have this code:
from credentials import *
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
import tweepy
from time import sleep
from credentials import *
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
my_file=open('The Story of the Volsungs.txt','r')
file_lines=my_file.readlines()
my_file.close()
def random_line(afile):
line = next(afile)
for num, aline in enumerate(afile):
if random.randrange(num + 2): continue
line = aline
return line
def tweet():
for line in file_lines:
try:
print(line)
if line != '\n':
api.update_status(line)
sleep(3600)
else:
pass
except tweepy.TweepError as e:
print(e.reason)
sleep(2)
tweet()
and it gives me this error (username not *'d out in the actual thing):
Traceback (most recent call last):
File "C:\\Users\J*****\Desktop\IzzieBot\TweetBot\run_bot.py", line 4, in <module>
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
NameError: name 'tweepy' is not defined
I don't know what's wrong or what it needs me to change, the error is so vague.
Upvotes: 1
Views: 6320
Reputation: 13327
Change the import order like below :
from credentials import *
import tweepy
from time import sleep
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
Upvotes: 2