diff --git a/.env b/.env new file mode 100644 index 0000000..c3968e7 --- /dev/null +++ b/.env @@ -0,0 +1,4 @@ +CONSUMER_KEY='XXXXXXXXXXXXXX' +CONSUMER_SECRET='XXXXXXXXXXXXXX' +ACCESS_TOKEN='XXXXXXXXXXXXXX' +ACCESS_TOKEN_SECRET='XXXXXXXXXXXXXX' diff --git a/README.md b/README.md index 97a5748..774f056 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,7 @@ tweets = api.get_tweets(query = 'Job Opportunities', count = 500) - Install **Tweepy** using pip command: `pip install tweepy` - Install **TextBlob** using pip command: `pip install textblob` +- Install **Python-DotEnv** usint pip command: `pip install python-dotenv` ### How to run? @@ -83,7 +84,7 @@ tweets = api.get_tweets(query = 'Job Opportunities', count = 500) - In order to fetch tweets through **Twitter API**, you need to register an App through your twitter account. - Follow this [link](https://apps.twitter.com/) to register your app. - Get the API keys. Need help, follow this [link](https://themepacific.com/how-to-generate-api-key-consumer-token-access-key-for-twitter-oauth/994/) -- Open `jobtweets.py` and replace '**XXXXXXXXXXXX**' with your API keys. +- Open `.env` and replace '**XXXXXXXXXXXX**' with your API keys. ```python diff --git a/jobtweets.py b/jobtweets.py index 02793e7..2112b48 100644 --- a/jobtweets.py +++ b/jobtweets.py @@ -1,7 +1,10 @@ +import os +from os.path import join, dirname import re import tweepy from tweepy import OAuthHandler from textblob import TextBlob +from dotenv import load_dotenv class TwitterClient(object): ''' @@ -11,12 +14,13 @@ def __init__(self): ''' Class constructor or initialization method. ''' - - consumer_key = 'XXXXXXXXXXXX' - consumer_secret = 'XXXXXXXXXXXX' - access_token = 'XXXXXXXXXXXX' - access_token_secret = 'XXXXXXXXXXXX' - + dotenv_path = join(dirname(__file__), '.env') + load_dotenv(dotenv_path) + + consumer_key = os.getenv('CONSUMER_KEY') + consumer_secret = os.getenv('CONSUMER_SECRET') + access_token = os.getenv('ACCESS_TOKEN') + access_token_secret = os.getenv('ACCESS_TOKEN_SECRET') try: