Esempio n. 1
0
def Cli():
    ver = sys.version_info

    if ver.major < 3:
        print("Python 3.x required. %d.%d.%d installed" % (ver.major, ver.minor, ver.micro))
        sys.exit(-1)

    parser = argparse.ArgumentParser(
        description='Blue State Digital API Client',
        epilog='(c) 2011 Blue State Digital')

    parser.add_argument('config',
                        nargs=1,
                        metavar='CONFIG',
                        help='Configuration file')

    parser.add_argument('-L', '--log-level',
                        default='warning',
                        help="'debug', 'error', 'warning', 'info', or 'critical'")

    parser.add_argument('-c', '--color',
                        action='store_true',
                        default=False,
                        help='Display with ANSI terminal colors.')

    parser.add_argument('-v', '--verbose',
                        action='store_true',
                        default=False,
                        help='Show verbose output.')

    parser.add_argument('-e', '--encode',
                        action='store',
                        default=None,
                        help='Enable UTF8 Encoding.')

    cli = parser.parse_args()
    logger = LoggerFactory().create(cli.log_level)
    logger.debug('CLI: %s' % cli)

    if not os.path.exists(cli.config[0]):
        logger.error("Error: configuration file %s does not exist." % (cli.config[0]))
        sys.exit(1)

    config = configparser.RawConfigParser()
    config.read(cli.config[0])

    settings = {
        'basic': {
            'host': 'localhost',
            'port': '80',
            'secure_port': '443'
        }
    }

    for key, value in config.items('basic'):
        settings['basic'][key] = value

    logger.debug('Settings: %s' % settings)

    apiFactory = BsdApiFactory()
    api = apiFactory.create(
        api_id=settings['basic']['api_id'],
        secret=settings['basic']['secret'],
        host=settings['basic']['host'],
        port=settings['basic']['port'],
        securePort=settings['basic']['secure_port'],
        colorize=cli.color,
        httpUsername=None,
        httpPassword=None,
        verbose=cli.verbose,
        encoding=cli.encode
    )

    console = Console({
        'api': api,
        'settings': settings
    })

    console.run()
Esempio n. 2
0
from xml.etree import ElementTree
import os, json, datetime, httplib, time, cPickle, re, itertools
from dateutil.parser import parse as parse_date
from bsdapi.BsdApi import Factory
from . import config

api = Factory().create(id=config.bsdid,
                       secret=config.bsdsecret,
                       host=config.bsdhost,
                       port=80,
                       securePort=443)

api.verbose = True

date_format = '%Y-%m-%d %H:%M:%S'


def get_search_results(date):
    # The higher you set this limit, the greater the risk of a network
    # timeout/failure, but the lower you  set it, the greater the risk
    # of too  many events on one  day causing the pagination  to fail.
    # (But that would be a nice problem to have!)
    req = dict(date_start=str(date), limit='13000')
    for dummy in 10 * [None]:
        resp = api.doRequest('/event/search_events', req, api.GET, None)
        # Sometimes  you  get a  temporary  'bad  gateway' from  this.
        # retry a few times.
        if not (resp.http_status == 502 and resp.http_reason == 'Bad Gateway'):
            break
            time.sleep(5)
    if resp.http_status != 200:
Esempio n. 3
0
from xml.etree import ElementTree
import os, json, datetime, httplib, time, cPickle, re, itertools
from dateutil.parser import parse as parse_date
from bsdapi.BsdApi import Factory
from . import config

api = Factory().create(id=config.bsdid, secret=config.bsdsecret,
                       host=config.bsdhost, port=80, securePort=443)

api.verbose=True

date_format = '%Y-%m-%d %H:%M:%S'

def get_search_results(date):
    # The higher you set this limit, the greater the risk of a network
    # timeout/failure, but the lower you  set it, the greater the risk
    # of too  many events on one  day causing the pagination  to fail.
    # (But that would be a nice problem to have!)
    req = dict(date_start=str(date), limit='13000')
    for dummy in 10*[None]:
        resp = api.doRequest('/event/search_events', req , api.GET, None)
        # Sometimes  you  get a  temporary  'bad  gateway' from  this.
        # retry a few times.
        if not (resp.http_status == 502 and resp.http_reason == 'Bad Gateway'):
            break
            time.sleep(5)
    if resp.http_status != 200:
        raise httplib.HTTPException, 'Event search failed:\n' + str(resp)
    return resp

nonexistent_re = re.compile(
Esempio n. 4
0
from bsdapi.BsdApi import Factory
import json
import xmltodict

import settings

api = Factory().create(
    id=settings.BSD_ID,
    secret=settings.BSD_SECRET,
    host=settings.BSD_HOST,
    port='80',
    securePort='443'
)


def check_credentials(form):
    resp = api.account_checkCredentials(form['email'], form['pw'])
    return resp.body


def create_account(form):

    if form['password1'] != form['password2']:
        return 'passwords do not match'
    resp = api.account_createAccount(form['email'], form['password1'], form['firstname'], form['lastname'], form['zip'])
    return resp.body


def fetch_constituent(creator_email):
    # resp = api.doRequest('cons/get_constituents_by_email', api.POST, body={"emails": creator_email})
def api_client():
    """
    :return: BsdApi
    """
    return Factory().create(API_ID, API_SECRET, API_HOST, 80, 443)
Esempio n. 6
0
def Cli():
    ver = sys.version_info

    if ver.major < 2 or (ver.major == 3 and ver.minor < 2) or (ver.major == 2 and ver.minor < 7):
        print("Python 2.7+ required. %d.%d.%d installed" %(ver.major, ver.minor, ver.micro))
        sys.exit(-1)

    parser = argparse.ArgumentParser(
        description = 'Blue State Digital API Client',
        epilog = '(c) 2011 Blue State Digital')

    parser.add_argument('config',
        nargs = 1,
        metavar = 'CONFIG',
        help='Configuration file')

    parser.add_argument('-L', '--log-level',
        default = 'warning',
        help = "'debug', 'error', 'warning', 'info', or 'critical'")

    parser.add_argument('-c', '--color',
        action = 'store_true',
        default = False,
        help = 'Display with ANSI terminal colors.')

    parser.add_argument('-v', '--verbose',
        action = 'store_true',
        default = False,
        help = 'Show verbose output.')

    cli = parser.parse_args()
    logger = LoggerFactory().create(cli.log_level)
    logger.debug( 'CLI: %s' % (cli) )

    if not os.path.exists(cli.config[0]):
        logger.error("Error: configuration file %s does not exist." % (cli.config[0]))
        sys.exit(1)

    config = configparser.RawConfigParser()
    config.read(cli.config[0])

    settings = {
        'basic' : {
            'host': 'localhost',
            'port': '80',
            'secure_port': '443'
        }
    }

    for key, value in config.items('basic'):
        settings['basic'][key] = value

    logger.debug( 'Settings: %s' % (settings) )

    apiFactory = BsdApiFactory()
    api = apiFactory.create(
        id = settings['basic']['api_id'], \
        secret = settings['basic']['secret'], \
        host = settings['basic']['host'], \
        port = settings['basic']['port'], \
        securePort = settings['basic']['secure_port'],
        colorize = cli.color
    )

    console = Console({
        'api': api,
        'settings': settings
    })

    console.run()