Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .env file to load twitter variables #38

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CONSUMER_KEY='XXXXXXXXXXXXXX'
CONSUMER_SECRET='XXXXXXXXXXXXXX'
ACCESS_TOKEN='XXXXXXXXXXXXXX'
ACCESS_TOKEN_SECRET='XXXXXXXXXXXXXX'
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand All @@ -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

Expand Down
16 changes: 10 additions & 6 deletions jobtweets.py
Original file line number Diff line number Diff line change
@@ -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):
'''
Expand All @@ -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:

Expand Down