# coding: utf-8
'''
Created on 06.03.2017

@author: d.gulyakin
'''
import json

def getUrlParam(session, paramName):
    paramValue = None
    try:
        if not isinstance(session, dict):
            urlParams = json.loads(session)["sessioncontext"]['urlparams']['urlparam']
        else:
            urlParams = session["sessioncontext"]['urlparams']['urlparam']
        if isinstance(urlParams, list):
            for params in urlParams:
                if params['@name'] == paramName:
                    paramValue = params['@value'][0]
                    break
        elif isinstance(urlParams, dict):
            if urlParams['@name'] == paramName:
                paramValue = urlParams['@value'][0]
    finally:
        return paramValue
