Skip to content

Commit

Permalink
Set logging levels
Browse files Browse the repository at this point in the history
  • Loading branch information
justjasongreen committed Jul 24, 2016
1 parent f50f9ad commit 20d616a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.rst
Expand Up @@ -54,7 +54,7 @@ Scrape

The 'scrape' command line utility can be used to populate a database with racing data scraped from the web. The syntax of the scrape command is:

scrape [-b] [-d <database_uri>] [-r <redis_uri>] date_from [date_to]
scrape [-b] [-d <database_uri>] [-q] [-r <redis_uri>] [-v] date_from [date_to]

The mandatory date_from and optional date_to arguments must be in the format YYYY-MM-DD, and define the (inclusive) range of dates to scrape data for.

Expand All @@ -64,6 +64,8 @@ The -d (or --database-uri=) option can be used to specify a URI for the target d

The -r (or --redis-uri=) option can be used to specify a URI for a redis server to be used for HTTP request caching. The default redis URI is redis://localhost:6379/predictive_punter. If a connection cannot be established with the specified redis server, the script will attempt to use the built in redislite service, or will run without HTTP request caching if the redislite service cannot be used.

The -q and -v (or --quiet and --verbose) options can be used to control the logging output generated by the scrape command. When the -q option is used, the logging level will be set to logging.WARNING. When the -v option is used, the logging level will be set to logging.DEBUG. By default, the logging level will be set to logging.INFO.


***********************
Development and Testing
Expand Down
12 changes: 11 additions & 1 deletion predictive_punter/command.py
@@ -1,6 +1,7 @@
import concurrent.futures
from datetime import datetime
from getopt import getopt
import logging
import time

import cache_requests
Expand Down Expand Up @@ -35,10 +36,11 @@ def parse_args(cls, args):
'database_uri': 'mongodb://localhost:27017/predictive_punter',
'date_from': datetime.now(),
'date_to': datetime.now(),
'logging_level': logging.INFO,
'redis_uri': 'redis://localhost:6379/predictive_punter'
}

opts, args = getopt(args, 'bd:r:', ['backup-database', 'database-uri=', 'redis-uri='])
opts, args = getopt(args, 'bd:qr:v', ['backup-database', 'database-uri=', 'quiet', 'redis-uri=', 'verbose'])

for opt, arg in opts:

Expand All @@ -48,9 +50,15 @@ def parse_args(cls, args):
elif opt in ('-d', '--database-uri'):
config['database_uri'] = arg

elif opt in ('-q', '--quiet'):
config['logging_level'] = logging.WARNING

elif opt in ('-r', '--redis-uri'):
config['redis_uri'] = arg

elif opt in ('-v', '--verbose'):
config['logging_level'] = logging.DEBUG

if len(args) > 0:
config['date_from'] = config['date_to'] = datetime.strptime(args[-1], '%Y-%m-%d')
if len(args) > 1:
Expand All @@ -60,6 +68,8 @@ def parse_args(cls, args):

def __init__(self, *args, **kwargs):

logging.basicConfig(level=kwargs['logging_level'])

database_client = pymongo.MongoClient(kwargs['database_uri'])
self.database = database_client.get_default_database()
self.do_database_backups = kwargs['backup_database']
Expand Down

0 comments on commit 20d616a

Please sign in to comment.