-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconnection.py
More file actions
26 lines (21 loc) · 732 Bytes
/
connection.py
File metadata and controls
26 lines (21 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import tweepy
import logging
logging.basicConfig(level=logging.INFO, filename='app.log',
filemode='w', format='%(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger()
def connect_account():
api_key = ''
api_secret_key = ''
access_token = ''
access_token_secret = ''
auth = tweepy.OAuthHandler(api_key, api_secret_key)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth, wait_on_rate_limit=True,
wait_on_rate_limit_notify=True)
try:
api.verify_credentials()
except Exception as e:
logger.error("Error creating API", exc_info=True)
raise e
logger.info("API created")
return api