Adding Confex API functions. Bug fixes. Clean up.
This commit is contained in:
293
app/methods/e_confex_methods.py
Normal file
293
app/methods/e_confex_methods.py
Normal file
@@ -0,0 +1,293 @@
|
||||
import datetime, json, pprint, pytz, random, requests, string, time
|
||||
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, validator
|
||||
|
||||
from app.db_sql import redis_lookup_id_random, sql_insert, sql_select, sql_update
|
||||
from app.lib_general import log, logging, logger_reset
|
||||
|
||||
|
||||
api = {}
|
||||
# api['base_url'] = 'https://aapor.confex.com/aapor/2023/meetingapi.cgi/[object]/[id]'
|
||||
api['base_url'] = 'https://aapor.confex.com/aapor/2023/meetingapi.cgi'
|
||||
api['headers'] = { 'Content-Type': 'application/json;charset=UTF-8' }
|
||||
api['username'] = None
|
||||
api['password'] = None
|
||||
|
||||
|
||||
# ### BEGIN ### API External Confex Methods ### get_event_session_list() ###
|
||||
# Updated 2023-04-11
|
||||
@logger_reset
|
||||
def get_event_session_list(
|
||||
):
|
||||
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
# if result := authenticate():
|
||||
# log.debug(result)
|
||||
# else:
|
||||
# return False
|
||||
|
||||
endpoint = '/Session'
|
||||
uri = api['base_url']+endpoint
|
||||
params = {}
|
||||
|
||||
confex_session_list = None
|
||||
|
||||
try_request = True
|
||||
max_tries = 5
|
||||
try_count = 0
|
||||
while try_request and try_count <= max_tries:
|
||||
try_count = try_count + 1
|
||||
|
||||
resp = requests.get(url=uri, params=params, headers=api['headers'])
|
||||
|
||||
log.debug(f'Status Code: {resp.status_code}')
|
||||
log.debug(f'Headers: {resp.headers}')
|
||||
# log.debug(f'Encoding: {resp.encoding}')
|
||||
# log.debug('Text:')
|
||||
# log.debug(resp.text)
|
||||
# log.debug(resp.json())
|
||||
|
||||
if resp.status_code == 200:
|
||||
log.info('Status 200')
|
||||
log.debug(resp.json())
|
||||
|
||||
confex_session_list_raw = resp.json() # .get('data').get('dataList')[0]
|
||||
# log.debug(confex_session_list_raw)
|
||||
|
||||
confex_session_list = confex_session_list_raw
|
||||
log.debug(confex_session_list)
|
||||
|
||||
try_request = False
|
||||
elif resp.status_code == 404:
|
||||
log.info('No results returned (status 404)')
|
||||
try_request = False
|
||||
confex_session_list = None
|
||||
elif resp.status_code == 429:
|
||||
log.warning('Hit rate limit. Sleeping for .1 seconds...')
|
||||
time.sleep(.1)
|
||||
try_request = True
|
||||
confex_session_list = False
|
||||
else:
|
||||
log.info('Not trying again')
|
||||
try_request = False
|
||||
confex_session_list = False
|
||||
|
||||
log.warning('Something may have gone wrong during the request.')
|
||||
|
||||
# log.warning('Something may have gone wrong. Setting the API app_user_token_datetime value to None to re-authenticate with Impexium on the next request.')
|
||||
# api['app_user_token_datetime'] = None # Resetting this just in case the App and or User token expired.
|
||||
|
||||
return confex_session_list
|
||||
# ### END ### API External Confex Methods ### get_event_session_list() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API External Confex Methods ### get_event_session_detail() ###
|
||||
# Updated 2023-04-11
|
||||
@logger_reset
|
||||
def get_event_session_detail(
|
||||
confex_session_id: str, # actually an auto number
|
||||
):
|
||||
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
# if result := authenticate():
|
||||
# log.debug(result)
|
||||
# else:
|
||||
# return False
|
||||
|
||||
endpoint = f'/Session/{confex_session_id}'
|
||||
uri = api['base_url']+endpoint
|
||||
params = {}
|
||||
|
||||
confex_session_detail = None
|
||||
|
||||
try_request = True
|
||||
max_tries = 5
|
||||
try_count = 0
|
||||
while try_request and try_count <= max_tries:
|
||||
try_count = try_count + 1
|
||||
|
||||
resp = requests.get(url=uri, params=params, headers=api['headers'])
|
||||
|
||||
log.debug(f'Status Code: {resp.status_code}')
|
||||
log.debug(f'Headers: {resp.headers}')
|
||||
# log.debug(f'Encoding: {resp.encoding}')
|
||||
# log.debug('Text:')
|
||||
# log.debug(resp.text)
|
||||
# log.debug(resp.json())
|
||||
|
||||
if resp.status_code == 200:
|
||||
log.info('Status 200')
|
||||
log.debug(resp.json())
|
||||
|
||||
confex_session_detail_raw = resp.json() # .get('data').get('dataList')[0]
|
||||
# log.debug(confex_session_detail_raw)
|
||||
|
||||
confex_session_detail = confex_session_detail_raw
|
||||
log.debug(confex_session_detail)
|
||||
|
||||
try_request = False
|
||||
elif resp.status_code == 404:
|
||||
log.info('No results returned (status 404)')
|
||||
try_request = False
|
||||
confex_session_detail = None
|
||||
elif resp.status_code == 429:
|
||||
log.warning('Hit rate limit. Sleeping for .1 seconds...')
|
||||
time.sleep(.1)
|
||||
try_request = True
|
||||
confex_session_detail = False
|
||||
else:
|
||||
log.info('Not trying again')
|
||||
try_request = False
|
||||
confex_session_detail = False
|
||||
|
||||
log.warning('Something may have gone wrong during the request.')
|
||||
|
||||
# log.warning('Something may have gone wrong. Setting the API app_user_token_datetime value to None to re-authenticate with Impexium on the next request.')
|
||||
# api['app_user_token_datetime'] = None # Resetting this just in case the App and or User token expired.
|
||||
|
||||
return confex_session_detail
|
||||
# ### END ### API External Confex Methods ### get_event_session_detail() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API External Confex Methods ### get_event_presentation_detail() ###
|
||||
# Updated 2023-04-11
|
||||
@logger_reset
|
||||
def get_event_presentation_detail(
|
||||
confex_session_id: str,
|
||||
confex_presentation_id: str, # similar to 'Paper/99999'
|
||||
):
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
# if result := authenticate():
|
||||
# log.debug(result)
|
||||
# else:
|
||||
# return False
|
||||
|
||||
endpoint = f'/Session/{confex_session_id}/{confex_presentation_id}'
|
||||
uri = api['base_url']+endpoint
|
||||
params = {}
|
||||
|
||||
confex_presentation_detail = None
|
||||
|
||||
try_request = True
|
||||
max_tries = 5
|
||||
try_count = 0
|
||||
while try_request and try_count <= max_tries:
|
||||
try_count = try_count + 1
|
||||
|
||||
resp = requests.get(url=uri, params=params, headers=api['headers'])
|
||||
|
||||
log.debug(f'Status Code: {resp.status_code}')
|
||||
log.debug(f'Headers: {resp.headers}')
|
||||
# log.debug(f'Encoding: {resp.encoding}')
|
||||
# log.debug('Text:')
|
||||
# log.debug(resp.text)
|
||||
# log.debug(resp.json())
|
||||
|
||||
if resp.status_code == 200:
|
||||
log.info('Status 200')
|
||||
log.debug(resp.json())
|
||||
|
||||
confex_presentation_detail_raw = resp.json() # .get('data').get('dataList')[0]
|
||||
# log.debug(confex_presentation_detail_raw)
|
||||
|
||||
confex_presentation_detail = confex_presentation_detail_raw
|
||||
log.debug(confex_presentation_detail)
|
||||
|
||||
try_request = False
|
||||
elif resp.status_code == 404:
|
||||
log.info('No results returned (status 404)')
|
||||
try_request = False
|
||||
confex_presentation_detail = None
|
||||
elif resp.status_code == 429:
|
||||
log.warning('Hit rate limit. Sleeping for .1 seconds...')
|
||||
time.sleep(.1)
|
||||
try_request = True
|
||||
confex_presentation_detail = False
|
||||
else:
|
||||
log.info('Not trying again')
|
||||
try_request = False
|
||||
confex_presentation_detail = False
|
||||
|
||||
log.warning('Something may have gone wrong during the request.')
|
||||
|
||||
# log.warning('Something may have gone wrong. Setting the API app_user_token_datetime value to None to re-authenticate with Impexium on the next request.')
|
||||
# api['app_user_token_datetime'] = None # Resetting this just in case the App and or User token expired.
|
||||
|
||||
return confex_presentation_detail
|
||||
# ### END ### API External Confex Methods ### get_event_presentation_detail() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API External Confex Methods ### get_event_presenter_detail() ###
|
||||
# Updated 2023-04-11
|
||||
@logger_reset
|
||||
def get_event_presenter_detail(
|
||||
confex_session_id: str,
|
||||
confex_presentation_id: str, # similar to 'Paper/99999'
|
||||
confex_presenter_id: str, # similar to 'Person/99999'
|
||||
):
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
# if result := authenticate():
|
||||
# log.debug(result)
|
||||
# else:
|
||||
# return False
|
||||
|
||||
endpoint = f'/Session/{confex_session_id}/{confex_presentation_id}/{confex_presenter_id}'
|
||||
uri = api['base_url']+endpoint
|
||||
params = {}
|
||||
|
||||
confex_presenter_detail = None
|
||||
|
||||
try_request = True
|
||||
max_tries = 5
|
||||
try_count = 0
|
||||
while try_request and try_count <= max_tries:
|
||||
try_count = try_count + 1
|
||||
|
||||
resp = requests.get(url=uri, params=params, headers=api['headers'])
|
||||
|
||||
log.debug(f'Status Code: {resp.status_code}')
|
||||
log.debug(f'Headers: {resp.headers}')
|
||||
# log.debug(f'Encoding: {resp.encoding}')
|
||||
# log.debug('Text:')
|
||||
# log.debug(resp.text)
|
||||
# log.debug(resp.json())
|
||||
|
||||
if resp.status_code == 200:
|
||||
log.info('Status 200')
|
||||
log.debug(resp.json())
|
||||
|
||||
confex_presenter_detail_raw = resp.json() # .get('data').get('dataList')[0]
|
||||
# log.debug(confex_presenter_detail_raw)
|
||||
|
||||
confex_presenter_detail = confex_presenter_detail_raw
|
||||
log.debug(confex_presenter_detail)
|
||||
|
||||
try_request = False
|
||||
elif resp.status_code == 404:
|
||||
log.info('No results returned (status 404)')
|
||||
try_request = False
|
||||
confex_presenter_detail = None
|
||||
elif resp.status_code == 429:
|
||||
log.warning('Hit rate limit. Sleeping for .1 seconds...')
|
||||
time.sleep(.1)
|
||||
try_request = True
|
||||
confex_presenter_detail = False
|
||||
else:
|
||||
log.info('Not trying again')
|
||||
try_request = False
|
||||
confex_presenter_detail = False
|
||||
|
||||
log.warning('Something may have gone wrong during the request.')
|
||||
|
||||
# log.warning('Something may have gone wrong. Setting the API app_user_token_datetime value to None to re-authenticate with Impexium on the next request.')
|
||||
# api['app_user_token_datetime'] = None # Resetting this just in case the App and or User token expired.
|
||||
|
||||
return confex_presenter_detail
|
||||
# ### END ### API External Confex Methods ### get_event_presenter_detail() ###
|
||||
Reference in New Issue
Block a user