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)
def test_username_password_exists(self): with pytest.raises(Exception) as excinfo1: API(None) with pytest.raises(Exception) as excinfo2: API(USERNAME) assert "username" in str(excinfo1.value) assert "password" in str(excinfo2.value)
def test_invalid_session(self): test_api = API(USERNAME, session_id="abc123", database=DATABASE) assert USERNAME in str(test_api.credentials) assert DATABASE in str(test_api.credentials) with pytest.raises(AuthenticationException) as excinfo: test_api.get("User") assert "Cannot authenticate" in str(excinfo.value) assert DATABASE in str(excinfo.value) assert USERNAME in str(excinfo.value)
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()
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()
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')
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" )
async def test_session_expired(self, async_populated_api): credentials = async_populated_api.credentials credentials.password = PASSWORD credentials.session_id = "abc123" test_api = API.from_credentials(credentials) users = await test_api.get_async("User") assert len(users) >= 1
def test_session_expired(self, async_populated_api): credentials = async_populated_api.credentials credentials.password = PASSWORD credentials.session_id = 'abc123' test_api = API.from_credentials(credentials, loop=async_populated_api.loop) users = run(test_api.get_async('User'), loop=async_populated_api.loop) assert len(users) >= 1
async def test_call_without_credentials(self): new_api = API(USERNAME, password=PASSWORD, database=DATABASE, server=None) user = await new_api.get_async("User", name="{0}".format(USERNAME)) assert len(user) == 1
async def test_api_from_credentials(self, async_populated_api): new_api = API.from_credentials(async_populated_api.credentials) users = await new_api.get_async("User") assert len(users) >= 1
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"
def test_api_from_credentials(self, async_populated_api): new_api = API.from_credentials(async_populated_api.credentials, loop=async_populated_api.loop) users = run(new_api.get_async('User'), loop=async_populated_api.loop) assert len(users) >= 1
def test_call_without_credentials(self): loop = asyncio.get_event_loop() or asyncio.new_event_loop() new_api = API(USERNAME, password=PASSWORD, database=DATABASE, server=None, loop=loop) user = run(new_api.get_async('User', name='{0}'.format(USERNAME)), loop=loop) assert len(user) == 1 assert len(user[0]) == 1
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,
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()