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)
Exemple #2
0
 def test_three_city_info(self):
     three.city("sf")
     info = os.environ["OPEN311_CITY_INFO"]
     self.assertTrue(info)
Exemple #3
0
 def test_three_services(self):
     three.city('sf')
     three.services()
     self.assertTrue(self.session.get.called)
Exemple #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)
Exemple #6
0
 def test_three_request_specific_report(self):
     three.city('macon')
     three.request('123abc')
     self.assertTrue(self.session.get.called)
Exemple #7
0
 def test_three_city_info(self):
     three.city('sf')
     info = os.environ['OPEN311_CITY_INFO']
     self.assertTrue(info)
Exemple #8
0
 def test_three_request_specific_report(self):
     three.city("macon")
     three.request("123abc")
     self.assertTrue(req.get.called)
Exemple #9
0
 def test_three_request_specific_report(self):
     three.city('macon')
     three.request('123abc')
     self.assertTrue(self.session.get.called)
Exemple #10
0
 def test_three_services(self):
     three.city('sf')
     three.services()
     self.assertTrue(self.session.get.called)
Exemple #11
0
 def test_three_requests(self):
     three.city('macon')
     three.requests()
     self.assertTrue(self.session.get.called)
Exemple #12
0
 def test_three_discovery(self):
     three.city('new haven')
     three.discovery()
     self.assertTrue(self.session.get.called)
Exemple #13
0
 def test_three_city_info(self):
     three.city('sf')
     info = os.environ['OPEN311_CITY_INFO']
     self.assertTrue(info)
Exemple #14
0
 def test_three_discovery(self):
     three.city("new haven")
     three.discovery()
     self.assertTrue(req.get.called)
Exemple #15
0
 def test_three_discovery(self):
     three.city('new haven')
     three.discovery()
     self.assertTrue(self.session.get.called)
Exemple #16
0
 def test_three_requests(self):
     three.city("macon")
     three.requests()
     self.assertTrue(req.get.called)
Exemple #17
0
 def test_three_requests(self):
     three.city('macon')
     three.requests()
     self.assertTrue(self.session.get.called)
Exemple #18
0
 def test_three_services(self):
     three.city("sf")
     three.services()
     self.assertTrue(req.get.called)
Exemple #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.