bonzanini / Book-SocialMediaMiningPython

Companion code for the book "Mastering Social Media Mining with Python"
546 stars 265 forks source link

Getting tweets from the timeline C2 code #2

Closed erniemagnotti closed 7 years ago

erniemagnotti commented 7 years ago

Working through the book and testing the code, I get the error below "No module named twitter_client" Can't seem to find the solution anywhere. Any help is appreciated!

from twitter_client import get_twitter client

ImportError Traceback (most recent call last)

in () ----> 1 from twitter_client import get_twitter_client ImportError: No module named twitter_client
bonzanini commented 7 years ago

Is the file twitter_client.py (link below) in the same folder?

https://github.com/bonzanini/Book-SocialMediaMiningPython/blob/master/Chap02-03/twitter_client.py

eolonade commented 7 years ago

Please how are we meant to set the environment variables in Windows?

The try part of the code didn't work and it kept returning the exception until I used consumer_key = 'TWITTER_CONSUMER_KEY' instead of consumer_key = os.environ['TWITTER_CONSUMER_KEY']. I also did the same for consumer_secret, access_token, and access_secret.

Here is the part of the code in question: https://github.com/bonzanini/Book-SocialMediaMiningPython/blob/master/Chap02-03/twitter_client.py

try: consumer_key = os.environ['TWITTER_CONSUMER_KEY'] consumer_secret = os.environ['TWITTER_CONSUMER_SECRET'] access_token = os.environ['TWITTER_ACCESS_TOKEN'] access_secret = os.environ['TWITTER_ACCESS_SECRET'] except KeyError: sys.stderr.write("TWITTER_* environment variables not set\n") sys.exit(1)

Thanks

bonzanini commented 7 years ago

@eolonade from your prompt: set TWITTER_CONSUMER_KEY=your-consumer-key and repeat for all the variables. This will be available for the active terminal only.

If you want to make it permanent: setx TWITTER_CONSUMER_KEY=your-consumer-key repeat for all the variables and start a new terminal.

If setx is not available you'll have to store the variables via your control panel / registry (different procedures for different Windows versions)