-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.py
32 lines (25 loc) · 848 Bytes
/
common.py
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
27
28
29
30
31
32
import logging
import logging.handlers
import twitter
import config
def get_api():
"""Returns an authenticated Twitter API instance"""
logger.info('Getting API')
api = twitter.Api(
config.CONSUMER_KEY,
config.CONSUMER_SECRET,
config.ACCESS_KEY,
config.ACCESS_SECRET,
tweet_mode="extended",
sleep_on_rate_limit=True)
logger.debug('Using Api: %s', api)
return api
def set_up_logging(log_file=None, level=logging.DEBUG):
global logger
logger = logging.getLogger(__name__)
logger.setLevel(level)
handler = logging.handlers.RotatingFileHandler(log_file, maxBytes=1048576, backupCount=5)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger