
    lhj8                         d dl Z d dlZd dlmZ d dlZdddddZ eej                  dk    r ed	            e	d
           ej        d
         Z
ddZd Zd Zd Zedk    r e             dS dS )    N)Errorzchge.atmonta_test_db_user	Ycze9_733monta_test_db)hostuserpassworddatabase   zDInvalid number of parameters. Usage: json2mysql.py <jsonArrayString>   c                 ~    | }|D ]7}t          |t                    r|                    |          }n|c S ||c S 8|S )z,Safely get a value from a nested dictionary.)
isinstancedictget)	data_dictkeysdefault	temp_dictkeys        %/var/www/html/webhhooks/json2mysql.pyget_nested_valuer      s^    I  i&& 	!c**IINNNNNN     c                 l   d}i d|                     d          d|                     d          d|                     d          d|                     d          d|                     d          d|                     d          d|                     d          d	|                     d	          d
|                     d
          d|                     d          d|                     d          dt          |ddg          dt          |ddg          dt          |ddg          dt          |ddg          dt          |ddg          dt          |ddg          i dt          |ddg          dt          |ddg          dt          |ddg          dt          |ddg          d t          |dd!g          d"t          |dd#g          d$t          |d%dg          d&t          |d%dg          d't          |d%d(g          d)|                     d)          d*|                     d*          d+|                     d+          d,|                     d,          d-|                     d-          d.|                     d.          d/|                     d/          d0|                     d0          |                     d1          |                     d2          |                     d3          |d4}|                     ||           t          d5|d                     d6S )7z1Inserts or updates a team record in the database.a  
    INSERT INTO teams (
        id, name, legalEmail, externalId, partnerExternalId, partnerCustomPayload,
        joinCode, recipientCode, companyName, taxIdentificationNumber, vatNumber,
        operator_id, operator_name, operator_identifier, operator_partnerId, operator_vatNumber,
        address_address1, address_address2, address_address3, address_city, address_province,
        address_zipCode, address_countryId,
        currency_identifier, currency_name, currency_decimals,
        type, category, operatorId, userId, isFrozen, frozenReason, frozenAt,
        blockedAt, createdAt, updatedAt, deletedAt, last_event_time
    ) VALUES (
        %(id)s, %(name)s, %(legalEmail)s, %(externalId)s, %(partnerExternalId)s, %(partnerCustomPayload)s,
        %(joinCode)s, %(recipientCode)s, %(companyName)s, %(taxIdentificationNumber)s, %(vatNumber)s,
        %(operator_id)s, %(operator_name)s, %(operator_identifier)s, %(operator_partnerId)s, %(operator_vatNumber)s,
        %(address_address1)s, %(address_address2)s, %(address_address3)s, %(address_city)s, %(address_province)s,
        %(address_zipCode)s, %(address_countryId)s,
        %(currency_identifier)s, %(currency_name)s, %(currency_decimals)s,
        %(type)s, %(category)s, %(operatorId)s, %(userId)s, %(isFrozen)s, %(frozenReason)s, %(frozenAt)s,
        %(blockedAt)s, %(createdAt)s, %(updatedAt)s, %(deletedAt)s, %(last_event_time)s
    )
    ON DUPLICATE KEY UPDATE
        name = VALUES(name), legalEmail = VALUES(legalEmail), externalId = VALUES(externalId),
        partnerExternalId = VALUES(partnerExternalId), partnerCustomPayload = VALUES(partnerCustomPayload),
        joinCode = VALUES(joinCode), recipientCode = VALUES(recipientCode), companyName = VALUES(companyName),
        taxIdentificationNumber = VALUES(taxIdentificationNumber), vatNumber = VALUES(vatNumber),
        operator_id = VALUES(operator_id), operator_name = VALUES(operator_name),
        operator_identifier = VALUES(operator_identifier), operator_partnerId = VALUES(operator_partnerId),
        operator_vatNumber = VALUES(operator_vatNumber), address_address1 = VALUES(address_address1),
        address_address2 = VALUES(address_address2), address_address3 = VALUES(address_address3),
        address_city = VALUES(address_city), address_province = VALUES(address_province),
        address_zipCode = VALUES(address_zipCode), address_countryId = VALUES(address_countryId),
        currency_identifier = VALUES(currency_identifier), currency_name = VALUES(currency_name),
        currency_decimals = VALUES(currency_decimals), type = VALUES(type), category = VALUES(category),
        operatorId = VALUES(operatorId), userId = VALUES(userId), isFrozen = VALUES(isFrozen),
        frozenReason = VALUES(frozenReason), frozenAt = VALUES(frozenAt), blockedAt = VALUES(blockedAt),
        createdAt = VALUES(createdAt), updatedAt = VALUES(updatedAt), deletedAt = VALUES(deletedAt),
        last_event_time = VALUES(last_event_time)
    idname
legalEmail
externalIdpartnerExternalIdpartnerCustomPayloadjoinCoderecipientCodecompanyNametaxIdentificationNumber	vatNumberoperator_idoperatoroperator_nameoperator_identifier
identifieroperator_partnerId	partnerIdoperator_vatNumberaddress_address1addressaddress1address_address2address2address_address3address3address_citycityaddress_provinceprovinceaddress_zipCodezipCodeaddress_countryId	countryIdcurrency_identifiercurrencycurrency_namecurrency_decimalsdecimalstypecategory
operatorIduserIdisFrozenfrozenReasonfrozenAt	blockedAt	createdAt	updatedAt	deletedAt)rI   rJ   rK   last_event_timezProcessed team ID: N)r   r   executeprint)cursorteam_payload
event_timesqldatas        r   insert_update_teamrT   &   s3   %CN'lt$$'  ((' 	l&&|44' 	l&&|44	'
 	\--.ABB' 	 0 01G H H' 	L$$Z00' 	))/::' 	|''66' 	"<#3#34M#N#N' 	\%%k22' 	'z46HII' 	),V8LMM' 	/z<>XYY' 	.|j+=VWW'  	.|j+=VWW!'" 	,\Iz;RSS#' '$ 	,\Iz;RSS%'& 	,\Iz;RSS''( 	(	67JKK)'* 	,\Iz;RSS+', 	+L9i:PQQ-'. 	-lY<TUU/'0 	/z<>XYY1'2 	),V8LMM3'4 	-lZ<TUU5'6 	  ((7'8 	L$$Z009': 	l&&|44;'< 	,""8,,='> 	L$$Z00?'@ 	((88A'B 	L$$Z00C'D 	\%%k22E' 'F "%%k22!%%k22!%%k22%M' ' 'DP NN3	
,T

,
,-----r   c           	      N   d}i d|                     d          d|                     d          d|                     d          dt          |ddg          dt          |ddg          d	t          |dd
g          dt          |ddg          dt          |ddg          d|                     d          d|                     d          d|                     d          d|                     d          d|                     d          d|                     d          d|                     d          d|                     d          d|                     d          i d|                     d          d|                     d          d|                     d          dt          j        |                     dg                     d|                     d          d|                     d          d|                     d          d|                     d          d |                     d           d!|                     d!          d"|                     d"          d#|                     d#          d$t          j        |                     d$g                     d%|                     d%          d&|                     d&          d'|                     d'          d(|}|                     ||           t          d)|d                     d*S )+z8Inserts or updates a team member record in the database.a[  
    INSERT INTO team_members (
        id, teamId, displayName,
        operator_id, operator_name, operator_identifier, operator_partnerId, operator_vatNumber,
        partnerExternalTeamId, userId, role, access, state, note,
        invitedAt, acceptedAt, rejectedAt, createdAt, updatedAt, deletedAt,
        chargePointIds, priceGroupId, costGroupId, teamMemberProfileId,
        canConfigureChargePoints, canPayWithTeamWallet, canManageTeamWallet,
        canRequestSponsoring, canManageTeamMembers, canPayForChargesCountryIds,
        teamWalletChargePaymentType, partnerExternalId, partnerCustomPayload,
        last_event_time
    ) VALUES (
        %(id)s, %(teamId)s, %(displayName)s,
        %(operator_id)s, %(operator_name)s, %(operator_identifier)s, %(operator_partnerId)s, %(operator_vatNumber)s,
        %(partnerExternalTeamId)s, %(userId)s, %(role)s, %(access)s, %(state)s, %(note)s,
        %(invitedAt)s, %(acceptedAt)s, %(rejectedAt)s, %(createdAt)s, %(updatedAt)s, %(deletedAt)s,
        %(chargePointIds)s, %(priceGroupId)s, %(costGroupId)s, %(teamMemberProfileId)s,
        %(canConfigureChargePoints)s, %(canPayWithTeamWallet)s, %(canManageTeamWallet)s,
        %(canRequestSponsoring)s, %(canManageTeamMembers)s, %(canPayForChargesCountryIds)s,
        %(teamWalletChargePaymentType)s, %(partnerExternalId)s, %(partnerCustomPayload)s,
        %(last_event_time)s
    )
    ON DUPLICATE KEY UPDATE
        teamId = VALUES(teamId), displayName = VALUES(displayName),
        operator_id = VALUES(operator_id), operator_name = VALUES(operator_name),
        operator_identifier = VALUES(operator_identifier), operator_partnerId = VALUES(operator_partnerId),
        operator_vatNumber = VALUES(operator_vatNumber), partnerExternalTeamId = VALUES(partnerExternalTeamId),
        userId = VALUES(userId), role = VALUES(role), access = VALUES(access), state = VALUES(state),
        note = VALUES(note), invitedAt = VALUES(invitedAt), acceptedAt = VALUES(acceptedAt),
        rejectedAt = VALUES(rejectedAt), createdAt = VALUES(createdAt), updatedAt = VALUES(updatedAt),
        deletedAt = VALUES(deletedAt), chargePointIds = VALUES(chargePointIds),
        priceGroupId = VALUES(priceGroupId), costGroupId = VALUES(costGroupId),
        teamMemberProfileId = VALUES(teamMemberProfileId), canConfigureChargePoints = VALUES(canConfigureChargePoints),
        canPayWithTeamWallet = VALUES(canPayWithTeamWallet), canManageTeamWallet = VALUES(canManageTeamWallet),
        canRequestSponsoring = VALUES(canRequestSponsoring), canManageTeamMembers = VALUES(canManageTeamMembers),
        canPayForChargesCountryIds = VALUES(canPayForChargesCountryIds),
        teamWalletChargePaymentType = VALUES(teamWalletChargePaymentType),
        partnerExternalId = VALUES(partnerExternalId), partnerCustomPayload = VALUES(partnerCustomPayload),
        last_event_time = VALUES(last_event_time)
    r   teamIddisplayNamer%   r&   r'   r   r(   r)   r*   r+   r,   r$   partnerExternalTeamIdrD   roleaccessstatenote	invitedAt
acceptedAt
rejectedAtrI   rJ   rK   chargePointIdspriceGroupIdcostGroupIdteamMemberProfileIdcanConfigureChargePointscanPayWithTeamWalletcanManageTeamWalletcanRequestSponsoringcanManageTeamMemberscanPayForChargesCountryIdsteamWalletChargePaymentTyper   r   rL   zProcessed team member ID: N)r   r   jsondumpsrM   rN   )rO   member_payloadrQ   rR   rS   s        r   insert_update_team_memberrn   {   s   'CR%n  &&%.$$X..% 	~))-88% 	'T8JKK	%
 	).:v:NOO% 	/\@Z[[% 	.~
K?XYY% 	.~
K?XYY% 	 !3!34K!L!L% 	.$$X..% 	""6**% 	.$$X..% 	##G,,% 	""6**% 	^''44%  	n((66!%" 	n((66#% %$ 	^''44%%& 	^''44'%( 	^''44)%, 	$*^%7%78H"%M%MNN-%. 	**>::/%0 	~))-881%2 	~112GHH3%4 	#N$6$67Q$R$R5%6 	 2 23I J J7%8 	~112GHH9%: 	 2 23I J J;%< 	 2 23I J J=%@ 	%dj1C1CD`bd1e1e&f&fA%B 	&~'9'9:W'X'XC%D 	^//0CDDE%F 	 2 23I J JG%H 	:I% %DL NN3	
3tDz
3
344444r   c                     d} d}	 t          j        t                    }t          d           t	          j        j        di t          } |                                 rt          d           | 	                    d          }|D ]}|
                    d          }|
                    d          }|
                    d          }|r|st          d	|            X|d
k    rt          |||           p|dk    rt          |||           t          d|            |                                  t          d           n# t          $ rU}t          d|            | r7|                                 r#|                                  t          d           Y d}~nd}~wt           j        $ r}t          d|            Y d}~ned}~wt"          $ rU}t          d|            | r7|                                 r#|                                  t          d           Y d}~nd}~ww xY w|r#|                                 t          d           | r9|                                 r'|                                  t          d           dS dS dS # |r#|                                 t          d           | r8|                                 r%|                                  t          d           w w w xY w)z7Main function to process JSON data and update database.NzConnecting to MySQL database...z#Successfully connected to database.T)
dictionary
entityTypepayload	eventTimez5Skipping event due to missing payload or entityType: teamzteam-memberzSkipping unknown entityType: zDatabase transaction committed.z/Error connecting to or interacting with MySQL: zTransaction rolled back.zError decoding JSON: zAn unexpected error occurred: zCursor closed.zDatabase connection closed. )rk   loadsjson_data_stringrN   mysql	connectorconnect	DB_CONFIGis_connectedrO   r   rT   rn   commitr   rollbackJSONDecodeError	Exceptionclose)
connectionrO   eventsevententity_typerr   rQ   es           r   mainr      s   JF41,-- 	/000_,99y99
""$$ 	57888&&$&77F   I I#ii55))I.."YY{33
 k YRWYYZZZ&((&vw
CCCC M11-fgzJJJJG+GGHHHH 3444 . . .CCCDDD 	.*1133 	.!!!,--- + + +)a))******** . . .2q22333 	.*1133 	.!!!,---	.  	$LLNNN"### 	1*1133 	1/00000	1 	1 	1 	1  	$LLNNN"### 	1*1133 	1/0000	1 	1sW   D<E J 
H(AFJ H(/GJ H(AH#J #H((J A"K1__main__)N)rk   mysql.connectorrx   r   sysr{   lenargvrN   exitrw   r   rT   rn   r   __name__ru   r   r   <module>r      s         ! ! ! ! ! ! 



  	 	 CMMQ	E
PQQQDGGG! 
 
 
 
R. R. R.jR5 R5 R5j81 81 81t zDFFFFF r   