Ejemplo n.º 1
0
    return script_stats


def update_stats(script_stats):
    script_stats['running_count'] = 0
    script_stats['processed_requests'] = processed_requests
    script_stats['last_completed_at'] = datetime.now().strftime(
        '%A, %d. %B %Y %H:%M:%S')
    db.scriptstats.save(script_stats)


if __name__ == '__main__':
    endpoints = ['bloomington', 'baltimore', 'boston']
    lm = LogManager()
    logger = lm.logger
    connection = Connection(os.environ['MONGO_URI'])
    db = connection[os.environ['MONGO_DATABASE']]
    while (True):
        for endpoint in endpoints:
            processed_requests = 0
            script_stats = increment_running_count_in_stats()
            logger.info('downloading requests from {0}...'.format(endpoint))
            city = three.city(endpoint)
            download_requests()
            logger.info('setting geospatial index on loc field')
            db.requests.ensure_index([("loc", GEO2D)])
            mark_requests_with_boundaries()
            update_stats(script_stats)
        logger.debug('requests downloaded; sleeping for 1 hour')
        sleep(3600)
Ejemplo n.º 2
0
 def test_three_city_info(self):
     three.city("sf")
     info = os.environ["OPEN311_CITY_INFO"]
     self.assertTrue(info)
Ejemplo n.º 3
0
 def test_three_services(self):
     three.city('sf')
     three.services()
     self.assertTrue(self.session.get.called)
Ejemplo n.º 4
0
"""SMSified logic for the MTA application."""

import os
import requests as req
import three


if 'PRODUCTION_ENV' in os.environ:
    # Then we'll use the actual SeeClickFix endpoint.
    macon = three.city('macon')
else:
    # Otherwise, it's testing.
    macon = three.dev('http://seeclicktest.com/open311/v2')


class AddressError(Exception):
    """Can't parse an address from a text message."""
    pass


class AuthenticationError(Exception):
    """
    Error should be raised when the SMSified username and password
    aren't known.
    """
    pass


def auth():
    """
    Get SMSified username and password authentication from environment
    script_stats['last_started_at'] = datetime.now().strftime('%A, %d. %B %Y %H:%M:%S')
    logger.debug(script_stats)
    db.scriptstats.save(script_stats)
    return script_stats

def update_stats(script_stats):
    script_stats['running_count'] = 0
    script_stats['processed_requests'] = processed_requests 
    script_stats['last_completed_at'] = datetime.now().strftime('%A, %d. %B %Y %H:%M:%S')
    db.scriptstats.save(script_stats)

if __name__ == '__main__':
    endpoints = ['bloomington', 'baltimore', 'boston']
    lm = LogManager()
    logger = lm.logger
    connection = Connection(os.environ['MONGO_URI'])
    db = connection[os.environ['MONGO_DATABASE']]
    while(True):
        for endpoint in endpoints:
            processed_requests = 0
            script_stats = increment_running_count_in_stats()
            logger.info('downloading requests from {0}...'.format(endpoint))
            city = three.city(endpoint)
            download_requests()
            logger.info('setting geospatial index on loc field')
            db.requests.ensure_index([("loc", GEO2D)])
            mark_requests_with_boundaries() 
            update_stats(script_stats)
        logger.debug('requests downloaded; sleeping for 1 hour')
        sleep(3600)
Ejemplo n.º 6
0
 def test_three_request_specific_report(self):
     three.city('macon')
     three.request('123abc')
     self.assertTrue(self.session.get.called)
Ejemplo n.º 7
0
 def test_three_city_info(self):
     three.city('sf')
     info = os.environ['OPEN311_CITY_INFO']
     self.assertTrue(info)
Ejemplo n.º 8
0
 def test_three_request_specific_report(self):
     three.city("macon")
     three.request("123abc")
     self.assertTrue(req.get.called)
Ejemplo n.º 9
0
 def test_three_request_specific_report(self):
     three.city('macon')
     three.request('123abc')
     self.assertTrue(self.session.get.called)
Ejemplo n.º 10
0
 def test_three_services(self):
     three.city('sf')
     three.services()
     self.assertTrue(self.session.get.called)
Ejemplo n.º 11
0
 def test_three_requests(self):
     three.city('macon')
     three.requests()
     self.assertTrue(self.session.get.called)
Ejemplo n.º 12
0
 def test_three_discovery(self):
     three.city('new haven')
     three.discovery()
     self.assertTrue(self.session.get.called)
Ejemplo n.º 13
0
 def test_three_city_info(self):
     three.city('sf')
     info = os.environ['OPEN311_CITY_INFO']
     self.assertTrue(info)
Ejemplo n.º 14
0
 def test_three_discovery(self):
     three.city("new haven")
     three.discovery()
     self.assertTrue(req.get.called)
Ejemplo n.º 15
0
 def test_three_discovery(self):
     three.city('new haven')
     three.discovery()
     self.assertTrue(self.session.get.called)
Ejemplo n.º 16
0
 def test_three_requests(self):
     three.city("macon")
     three.requests()
     self.assertTrue(req.get.called)
Ejemplo n.º 17
0
 def test_three_requests(self):
     three.city('macon')
     three.requests()
     self.assertTrue(self.session.get.called)
Ejemplo n.º 18
0
 def test_three_services(self):
     three.city("sf")
     three.services()
     self.assertTrue(req.get.called)
Ejemplo n.º 19
0
"""SMSified logic for the MTA application."""

import os
import requests as req
import three

if 'PRODUCTION_ENV' in os.environ:
    # Then we'll use the actual SeeClickFix endpoint.
    macon = three.city('macon')
else:
    # Otherwise, it's testing.
    macon = three.dev('http://seeclicktest.com/open311/v2')


class AddressError(Exception):
    """Can't parse an address from a text message."""
    pass


class AuthenticationError(Exception):
    """
    Error should be raised when the SMSified username and password
    aren't known.
    """
    pass


def auth():
    """
    Get SMSified username and password authentication from environment
    variables.