o
    eO                     @   s   d dl mZ d dlmZmZ d dlmZ d dlZd dlm	Z	 d dl
mZ d dlZd dlZd dlZG dd deZG d	d
 d
eZdS )    )render)HttpResponseJsonResponse)ViewN)Image)FirebaseManagerc                   @      e Zd Zdd Zdd ZdS )OcrViewc                 C   s   t ddiS )NmessageREQUEST_ERROR)r   )selfrequest r   +/home/api_server/kakao_chatbot/ocr/views.pyget      zOcrView.getc           
      C   s   t |j}|d d d }t |}|dd}|dr)|dr)|dd	 }|s1td
diS t|}|jdkr_t	
t|j}tj|dd}t| dddd|iigid}	t|	S tddiS )Nactionparamsget_img
secureUrls zList()   erroru)   이미지 URL을 찾을 수 없습니다.   zeng+kor)lang2.0outputs
simpleTexttextversiontemplater
   	KEY_ERROR)jsonloadsbodyr   
startswithendswithr   requestsstatus_coder   openioBytesIOcontentpytesseractimage_to_stringprint)
r   r   datasecure_urls_strsecure_urls_dictsecure_urlsresponseimgr    responseBodyr   r   r   post   s0   


zOcrView.postN)__name__
__module____qualname__r   r:   r   r   r   r   r	          r	   c                   @   r   )OcrUserCheckc                 C   s   t  | _d S )N)r   firebaseManager)r   r   r   r   __init__0   r   zOcrUserCheck.__init__c              	   C   s   t |j}|d d d }| j|}|d r6dddd|d	 d
diddddgdigid}t|S dddddiigid}t|S )NuserRequestuseridr   r   r   	basicCardu   {}님 안녕하세요   imageUrlzfhttps://avatars.githubusercontent.com/u/141043183?s=400&u=56efb37f8ba9145f99c5e5e19ba875986825d85c&v=4blocku   OCR 시작하기652f32d7b3ba010afdf6e56d)r   labelblockId)title	thumbnailbuttonsr!   r   r    u   CATS 회원이 아닙니다)r%   r&   r'   r@   	userCheckformatr   )r   r   r3   user_id
user_checkjsonBodyr   r   r   r:   2   s>   #zOcrUserCheck.postN)r;   r<   r=   rA   r:   r   r   r   r   r?   /   r>   r?   )django.shortcutsr   django.httpr   r   django.viewsr   r0   PILr   userInfo.viewsr   r%   r*   r-   r	   r?   r   r   r   r   <module>   s    "