U
    앐d5                     @   s  d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZ ddlmZmZmZmZmZmZmZmZmZmZmZmZ dd	d
dddddgddddddgdddddddddddd d!g
dd"d#d$d%gdd&d&d'd(gdd)d*d+d,d-gdd.d/d0d1gdd2d3d4d5d6d7gdd8d9d:gdd;d<d
d=d>d?gdd@dAdBgddCdDdEdFdGgdgZG dHdI dIeZG dJdK dKeZdLdM ZdNdO ZdPdQ ZG dRdS dSeZG dTdU dUeZ G dVdW dWeZ!G dXdY dYeZ"G dZd[ d[eZ#G d\d] d]eZ$G d^d_ d_eZ%dS )`    Nrender)TemplateView)JsonResponse)View   )speech_wordsexcel_to_json_epgexcel_to_json_viewsadd_show_to_viewsadd_calcul_to_epggenerate_static_jsonget_excel_adscount_ads_by_brandget_brands_by_idget_week_datescount_ads_by_dateread_json_file zSelect a Categorie)idnameZtelecommunicationsZTelecommunicationsZInwiZOrangezMaroc-Telecom)r   r   brandsZ
automotiveZ
AutomotiveZDaciaZSkodaZpeugeotzfood-and-beveragezFood and BeverageZAichaZDariStarZKaynaz
La prairieZAstaZLeader_ChipsZLesieurZKinderZConikosZtravelZTravelZoncefZramZHomeZrichbondZLbassmazhealth-and-beautyzHealth and BeautyZGarnierZorielZMiaz"laundry-detergents-and-fabric-carez"Laundry detergents and fabric careZArialZMioZretailZRetailZ	CarrefourZMarjanezElectro-planetzmorocco-mallZ	educationZ	EducationZOFPPTZ
governmentZ
Governmentz
non-profitz
Non-profitZNARSAZgazZGazz	Tisir-gazZfinanceZFinancez	cash plusZchaabiZsendwavec                       s    e Zd ZdZ fddZ  ZS )DashboardViewzpages/index.htmlc                    s   i }t  jf |}||d< |S Ndatasuperget_context_dataselfkwargsr   context	__class__ D/var/www/html/Presentation_Sanoa_Al_oula/src/apps/dashboard/views.pyr   f   s    zDashboardView.get_context_data__name__
__module____qualname__template_namer   __classcell__r%   r%   r#   r&   r   c   s   r   c                       s    e Zd ZdZ fddZ  ZS )PiracyControlViewzpages/piracy_control.htmlc                    s   i }t  jf |}||d< |S r   r   r   r#   r%   r&   r   s   s    z"PiracyControlView.get_context_datar'   r%   r%   r#   r&   r-   p   s   r-   c                    sf   t d g }tD ]H}|dg }|ddkr8||  fdd|D }|r|| qt|ddS )	NF/var/www/html/Presentation_Mo_V2/src/media/media_planning_14-21_v2.csvr   r   r   c                    s&   g | ] t  fd dD r qS )c                 3   s   | ]}| d  kV  qdS )ZBrandN)get).0adZbrandr%   r&   	<genexpr>   s     z,get_categories.<locals>.<listcomp>.<genexpr>)any)r0   ads_datar2   r&   
<listcomp>   s      z"get_categories.<locals>.<listcomp>Fsafe)r   categories_datar/   appendr   )requestZupdated_categoriescategoryr   Zmatching_brandsr%   r5   r&   get_categories|   s    
r>   c                 C   s0   g }t D ]}d|kr||d  qtd|iS )z=
    Returns a list of all brands across all categories.
    r   )r:   extendr   )r<   Z
all_brandsr=   r%   r%   r&   
get_brands   s
    r@   c                 C   s>   t D ],}|d |krd|krtd|d i  S qtdg iS )zK
    Returns a list of brands associated with the given category name.
    r   r   )r:   r   )r<   category_idr=   r%   r%   r&   get_brands_by_category   s    rB   c                   @   s   e Zd Zdd Zdd ZdS )MediaPlanningViewc                 C   s   d}i }t |||S )Nzpages/media_planning.htmlr   r    r<   r+   r"   r%   r%   r&   r/      s    zMediaPlanningView.getc                    s8  |j d}|j d}|j d}|j d}|j d}td}|r|dkr|dkrhd	tt|n|}t||}	d
|	d}
n|r|dkrt  dt|t	|dg}	d|	d}
nv|r(|dkr(dd l
 dddddddg}d}g }	|D ].} fddt|D }||d}|	| qd|	d}
ni }
t|
ddS )NrA   r   weekdayvaluer.   Zcomparison_brands_categoryr   ,ZPieAdsChart)Zchartr   Zcolumns_ads_chartz	Ads Count)r   r   ZColumnsAdsChartZspline_ads_chartr   MonTueWedThuFriSatSun   c                    s   g | ]}  d dqS )r      )randint)r0   _randomr%   r&   r7      s     z*MediaPlanningView.post.<locals>.<listcomp>ZSplineAdsChartapplication/jsoncontent_type)POSTr/   r   joinr   r:   r   printr   r   rU   ranger;   r   )r    r<   rA   Zbrands_listZselected_weekZselected_dayZ
chart_typer6   Z	brand_strZ
chart_dataresponsenamesZnum_data_pointsr   Zdata_pointsitemr%   rT   r&   post   sD    

zMediaPlanningView.postNr(   r)   r*   r/   r`   r%   r%   r%   r&   rC      s   rC   c                   @   s   e Zd Zdd Zdd ZdS )VideoAnalysisViewc                 C   s   d}i }t |||S )Nzpages/video_analysis.htmlr   rD   r%   r%   r&   r/      s    zVideoAnalysisView.getc              	   C   sJ   t dddd}tdd}| }W 5 Q R X t|}||d}t|dd	S )
Nuy   /var/www/html/Presentation_Sanoa_Al_oula/src/media/Jt_en_Français_Al_Aoula_du_18_06_2023_2_min_2023_06_19_15_49_04.jsonzi/var/www/html/Presentation_Mo_V2/src/media/Info_Soir_Dimanche_07_Mai_2023_2023_05_08_19_46_02_static.jsonP   )Zconfidence_valueux   /var/www/html/Presentation_Sanoa_Al_oula/src/media/Jt_en_Français_Al_Aoula_du_18_06_2023_2_min_2023_06_19_15_49_04.txtr)detected_objectsr   rV   rW   )r   openreadr   r   )r    r<   re   filetextZobj_speech_wordsanalysis_resultsr%   r%   r&   r`      s    zVideoAnalysisView.postNra   r%   r%   r%   r&   rb      s   rb   c                   @   s   e Zd Zdd Zdd ZdS )CommentsAnalyzerViewc                 C   s   d}i }t |||S )Nzpages/comments_analyzer.htmlr   rD   r%   r%   r&   r/   
  s    zCommentsAnalyzerView.getc              	   C   s   |j d}td td|  td tdd}| }W 5 Q R X zt|}d|dd	}W n* tj	k
r   d|
d
ddd	}Y nX t|ddS )NresultsZpython3_startz7python3 /var/www/html/exportcomments/youtube_export.py Zpython3_endz'/var/www/html/exportcomments/temp2.jsonrd   Tjson)successr   typerH   z,
ri   Fr8   )rY   r/   r[   ossystemrf   rg   rm   loadsJSONDecodeErrorreplacer   )r    r<   urlfZfile_contentsZ	json_datarj   r%   r%   r&   r`     s    
zCommentsAnalyzerView.postNra   r%   r%   r%   r&   rk     s   rk   c                   @   s   e Zd Zdd Zdd ZdS )VideoSubtitlesViewc                 C   s   d}i }t |||S )Nzpages/video_subtitles.htmlr   rD   r%   r%   r&   r/   J  s    zVideoSubtitlesView.getc                 C   s   d S Nr%   r    r<   r%   r%   r&   r`   O  s    zVideoSubtitlesView.postNra   r%   r%   r%   r&   rw   H  s   rw   c                   @   s   e Zd Zdd Zdd ZdS )MusicRemovalViewc                 C   s   d}i }t |||S )Nzpages/music_removal.htmlr   rD   r%   r%   r&   r/   U  s    zMusicRemovalView.getc                 C   s   d S rx   r%   ry   r%   r%   r&   r`   Z  s    zMusicRemovalView.postNra   r%   r%   r%   r&   rz   S  s   rz   c                   @   s   e Zd Zdd Zdd ZdS )DynamicAdInsertionViewc                 C   s   d}i }t |||S )Nzpages/dynamicAdInsertion.htmlr   rD   r%   r%   r&   r/   `  s    zDynamicAdInsertionView.getc                 C   s   d S rx   r%   ry   r%   r%   r&   r`   e  s    zDynamicAdInsertionView.postNra   r%   r%   r%   r&   r{   ^  s   r{   c                   @   s    e Zd ZdZdd Zdd ZdS )
ReportViewzpages/reports.htmlc                 C   s>   ddt dd tddddt d	d td
dd}|S )Nu'   Aicha - Ep 12 - عايشة الحلقةz8AVn-iXYFo0zI/var/www/html/Presentation_Sanoa_Al_oula/src/media/reports/Aicha-Ep12.txtrd   zJ/var/www/html/Presentation_Sanoa_Al_oula/src/media/reports/Aicha-Ep12.json)titleZ	video_srcreportcommentsu<   Chef Academy - Prime  شاف أكاديمي - برايم 1Zo3S06MQsStEzR/var/www/html/Presentation_Sanoa_Al_oula/src/media/reports/Chef_Academy_Prime1.txtzS/var/www/html/Presentation_Sanoa_Al_oula/src/media/reports/Chef_Academy_Prime1.json)zAicha - Ep 12zChef Academy - Prime 1)rf   rg   r   )r    reports_dictr%   r%   r&   get_reports_dictl  s    zReportView.get_reports_dictc                 C   s&   |   }d||i i}t|| j|S )Nr~   )r   r/   r   r+   )r    r<   Z	show_namer   r"   r%   r%   r&   r/   }  s    zReportView.getN)r(   r)   r*   r+   r   r/   r%   r%   r%   r&   r|   i  s   r|   )&datetimerp   rm   ZjsonlintZdjango.shortcutsr   Zdjango.views.genericr   django.httpr   django.viewsr   utilsr   r	   r
   r   r   r   r   r   r   r   r   r   r:   r   r-   r>   r@   rB   rC   rb   rk   rw   rz   r{   r|   r%   r%   r%   r&   <module>   s    8	
QD@