U
    Ch>                  
   @   s   d dl Z d dl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	m
Z
 d dlZdddZed	Zzee W n* ek
r Z zee W 5 dZ[X Y nX e Zd
Zdd ZdS )    N)	firestore)credentials)FieldFilter)Counterd   c              (      s   ddddddddd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(h( t d)|  } fd*d+|D }t|}d,d+ ||D S )-Naanthewewereyouyouryourshesheittheythemhisherourourstheirwasisareambebeentoinofandoronforwithasbyatfromthisthatthesethosez\b\w+\bc                    s   g | ]}| kr|qS  r/   ).0word	stopwordsr/   K/home/ankuromar296_gmail_com/publish_blogs_ai/gsc/get_jeevnai_advisories.py
<listcomp>   s      z get_keywords.<locals>.<listcomp>c                 S   s   g | ]\}}|qS r/   r/   )r0   r1   _r/   r/   r4   r5       s     )refindalllowerr   most_common)textZtop_nwordsZfiltered_wordsZword_countsr/   r2   r4   get_keywords   sZ                                        r=   zservicekey.jsonzShttps://us-central1-farmbase-b2f7e.cloudfunctions.net/create_advisory_blog_predata2c                  C   s  t t } t | d }dd|| dd}tjt|d}g }g }z| }|dd }|d k	r| D ]\}}	g }
|	D ]b}t|}t	
djtd	d
|d }|D ]2}| }d|d< d|d< d|d< |
t| qqtd|
i}|| qd|dfW S    tt  Y nX d S )Ni / T
      )Z	isTestingZRequiredBlogsCountZFromTimeZToTimeZAvoidFromDays)jsonZCropsZJEEVN_AI_advisories	timestampz==)filterNoneUIDZfieldIDZ	fieldNamebody )inttimerequestsposturlr@   getitemsstrdb
collectionwherer   to_dictappendprint	traceback
format_exc)to_timeZ	from_timepayloadresponseZall_contentall_keywordsZresponse_jsonZ
crop_blogsZ	crop_nameZcrop_blog_keysZfinal_advisories_arrZ
single_keyZadvisory_refdocZadvisory_objcontent_objr/   r/   r4   get_jeevnai_advisories-   sB    	 
r]   )r   )rI   rH   Zgoogle.cloudr   Zfirebase_adminr   Z$google.cloud.firestore_v1.base_queryr   rU   collectionsr   r7   r=   ZCertificateZcredZinitialize_app	ExceptionerT   ClientrO   rK   r]   r/   r/   r/   r4   <module>   s"   

