o
    	e?                     @   s   d dl mZ d dlmZ d dlmZ d dlZd dlZd dlm	Z	 d dl
mZ d dlZd dlmZmZ d dlmZ d d	lmZ d d
lmZ G dd deZG dd deZG dd deZG dd deZdS )    )render)View)JsonResponseN)FirebaseManager)pushNotificationView)credentials	firestore)	messaging)FACE_DETECTION_SERVER_URL)FIREBASE_CREDENTIALS_PATHc                   @   s&   e Zd Zd	ddZdd Zdd ZdS )
testViewreturnNc                 C   s   t  | _d S N)r   fm)self r   2/home/api_server/kakao_chatbot/testingApp/views.py__init__   s   ztestView.__init__c                 C   s   | j ddi}tddiS )Ndata	   졸업식 )r   getScheduler   )r   requestschedul_dictr   r   r   post   s   ztestView.postc                 C   s4   | j ddi}|d }| j |}t| t|S )Nr   r   friends)r   r   getTokenprintr   )r   r   r   friends_listfriends_token_dictr   r   r   get   s
   ztestView.get)r   N)__name__
__module____qualname__r   r   r    r   r   r   r   r      s    
r   c                   @   s   e Zd Zdd ZdS )faceDetectionc                 C   s   t |j}d|d d  vrtddiS |d d d }t |}|dd}|dr9|d	r9|d
d }|sAtddiS z%d|i}|jt	t 
|d}|jdkr^tddi W d S tddi W d S    tddi Y d S )Nget_imgactionparamsmessageKEYERROR
secureUrlsr   zList()   erroru)   이미지 URL을 찾을 수 없습니다.url)r      valzSERVER RESPONSE ERRORz(CANNOT CONNECT FACE_DETECTION_SERVER_URL)jsonloadsbodykeysr   r    
startswithendswithr   r
   dumpsstatus_code)r   r   r   secure_urls_strsecure_urls_dictsecure_urlsresponseBodyresponser   r   r   r   #   s$    

zfaceDetection.postN)r!   r"   r#   r   r   r   r   r   r$   "   s    r$   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
pushNotificationc                 C   "   t jstt}t | d S d S r   firebase_admin_appsr   Certificater   initialize_appr   credr   r   r   r   :      
zpushNotification.__init__c                 C   s4   |}t jt jddd|d}t |}td| |S )Nzit is titlez
code smelltitler4   )notificationtokenzSuccessfully sent message:)r	   MessageNotificationsendr   )r   rL   registration_tokenr(   r>   r   r   r   sendToFirebaseCloudMessaging>   s   

z-pushNotification.sendToFirebaseCloudMessagingc                 C   D   t |jd}|d }td|  | |}t| tddiS Nutf-8rL   r>   zgood:r2   r3   r4   decoder   rQ   r   r   r   r   rL   r>   r   r   r   r    L      
zpushNotification.getc                 C   rR   rS   rU   rW   r   r   r   r   S   rX   zpushNotification.postN)r!   r"   r#   r   rQ   r    r   r   r   r   r   r?   9   s
    r?   c                   @   s   e Zd Zdd Zdd ZdS )pushNotificationToAllc                 C   r@   r   rA   rF   r   r   r   r   \   rH   zpushNotificationToAll.__init__c                 C   st   t |jd}t }| }tjtj|d |d dt	|
 d}t|}td|j t|j|jdS )NrT   rJ   contentsrI   )rK   tokensz#{0} messages were sent successfully)sucess_countfailure_count)r2   r3   r4   rV   r   r   r	   MulticastMessagerN   listvaluessend_multicastr   formatsuccess_countr   r]   )r   r   r   fbfcm_token_dictr(   r>   r   r   r   r   a   s   

zpushNotificationToAll.postN)r!   r"   r#   r   r   r   r   r   r   rY   [   s    rY   )django.shortcutsr   django.viewsr   django.httpr   r2   requestsuserInfo.viewsr   	fcm.viewsr   rB   r   r   r	   kakao_chatbot.settingsr
   r   r   r$   r?   rY   r   r   r   r   <module>   s     "