예제 #1
0
def main():
    log.info(f"main() is started")
    """
        env docker에서는 -e 옵션 그냥 맥에서 실행할때는 export
    """
    source_username = os.environ['S_USER']
    source_password = os.environ['S_PASS']
    source_database = os.environ['S_DATABASE']
    source_table = os.environ['S_TABLE']

    try:
        api = API(database=source_database,
                  username=source_username,
                  password=source_password)
        api.authenticate()
    except Exception as e:
        log.error(e)
        raise e
    """
        최대 에러 수 는 100회로 제한
        재접속 성공 시 초기화
    """
    max_feed_error_count = 0
    while max_feed_error_count < 100:
        try:
            feed.DataFeed(api,
                          CustomDataDataFeedListener(api),
                          source_table,
                          interval=12).start(threaded=False)
            max_feed_error_count = 0
        except Exception as e:
            log.error(e)
            log.info('max_feed_error_count : ' + str(max_feed_error_count))
            max_feed_error_count += 1
            time.sleep(6)
예제 #2
0
def main(database, user=None, password=None, server=None, interval=60):
    api = API(database=database,
              username=user,
              password=password,
              server=server)
    api.authenticate()
    feed.DataFeed(api,
                  ExceptionDataFeedListener(api),
                  "ExceptionEvent",
                  interval=interval).start()
예제 #3
0
def main(database='layetest',
         user='******',
         password='******',
         server=None,
         interval=60):
    api = API(database=database,
              username=user,
              password=password,
              server=server)
    api.authenticate()
    feed.DataFeed(api, DataFeedListener(api), "LogRecord",
                  interval=interval).start()
예제 #4
0
def async_populated_api():
    loop = asyncio.get_event_loop() or asyncio.new_event_loop()
    if USERNAME and PASSWORD:
        session = API(USERNAME, password=PASSWORD, database=DATABASE, server=None, loop=loop)
        try:
            session.authenticate()
        except MyGeotabException as exception:
            pytest.fail(exception)
            return
        yield session
    else:
        pytest.skip('Can\'t make calls to the API without the '
                    'MYGEOTAB_USERNAME and MYGEOTAB_PASSWORD '
                    'environment variables being set')
예제 #5
0
def async_populated_api():
    if USERNAME and PASSWORD:
        session = API(USERNAME, password=PASSWORD, database=DATABASE, server=None)
        try:
            session.authenticate()
        except MyGeotabException as exception:
            pytest.fail(exception)
            return
        yield session
    else:
        pytest.skip(
            "Can't make calls to the API without the "
            "MYGEOTAB_USERNAME and MYGEOTAB_PASSWORD "
            "environment variables being set"
        )
예제 #6
0
 def test_auth_exception(self):
     test_api = API(USERNAME, password="******", database="this_database_does_not_exist")
     with pytest.raises(MyGeotabException) as excinfo:
         test_api.authenticate(False)
     assert excinfo.value.name == "DbUnavailableException"
import asyncio
from mygeotab import API, dates
import json
import csv
from datetime import date, timedelta
import os
from config import *

#create folder for containing results
if not os.path.exists('data'):
    os.makedirs('data')

devices = []
client = API(username=username, password=password, database=database)
client.authenticate()

#find all devices visible to the service account
device = client.call('Get', typeName='Device')
for j in device:
    devices.append([j['name'], j['id']])

#iterate over the data range
while start_date <= end_date:
    fromdate = start_date.strftime("%Y-%m-%d") + "T00:00:00.000Z"
    todate = (start_date + data_range).strftime("%Y-%m-%d") + "T00:00:00.000Z"
    for dev in devices:
        result = []
        filename = start_date.strftime("%Y-%m-%d") + "-" + dev[0]
        query = client.get("LogRecord",
                           search={
                               "fromDate": fromdate,
예제 #8
0
def main(database, user=None, password=None, server=None, interval=60):
    api = API(database=database, username=user, password=password, server=server)
    api.authenticate()
    feed.DataFeed(api, ExceptionDataFeedListener(api), 'ExceptionEvent', interval=interval).start()