a
    }h                     @   s   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZ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mZ d dlmZmZ d dlmZmZmZmZmZ d dlmZmZ G d	d
 d
Z dS )    N)Image)close_old_connections)Q)FifaAccountConsoleReadingAccounts)BASE_DIR	TIME_ZONE)set_sbc_statusenter_world_xboxsget_last_emailget_image_positionenter_double_check_code_xbox)	new_printget_db_timec                   @   s8   e Zd Zdd ZdddZdd	 Zd
d ZdddZdS )ConsoleAccountsUtilsc                 C   s4   ddl m} || _| jj| _| jj| _| jj| _d S )Nr   )PublicMoves)utils.public_movesr   public_movesfifa_account
sbc_workerps4_buttons)selfpublic_moves_instancer    r   RC:\Users\Administrator\Downloads\futplus_django\accounts\console_accounts_utils.py__init__   s
    

zConsoleAccountsUtils.__init__TFr   c                 C   s  t | jd|d| t| jd |dkr>td t | jd dS | j }|rX|rv|dkrv| j  t	
d | j  tdD ]}| j  t	
d	 q~td
D ]}t	
d	 | j  q| jjdd | jjdd | jjdd td
D ]"}| j  | j  t	
d	 q| jjd
d tdD ]}| j  | jjtjtddddrtd t | jd td}|ddddf }	td|	 | jjdddd}
|r4| jjtjtddddrtd t | jd nRt|
d t |
d|
 d | jjdd |dkr&td  t | jd   d S q&nt|
  }d!|v s|d"r`|rd"|vszd"|v r |s d#|vr d$|vr d%|vr d&|vr tt d'| }rt d'| }! nd(d)k r t|d t | jd| d | jjdd |dkr&td   d S q&n$td| d* t | jd| d* | jjd
d | j  | jjtjtd+dddrt | jd|
 d, | jj"dd | jjd
d | jjd
d n0t	
d | j#|||d d-}|dkr&|  S q&d S ).Nzremoving accounts , keys : z , failed only : zremoving accounts   ztoo many tryps4_main   
         ?      )sleep_afterd   z+utils/xbox_public/select_remove_account.pngscreen_shot_tmp.jpg?	thresholdzselecting account for removei  i  iR  i.  zcrop_account_name_tmp.jpgz--psm 10 --oem 3T)configconvertz%utils/xbox_public/empty_user_icon.pngz!empty account found , removing itz will not removedzaccount :   zno account foundstartkeyZxboxseriesZballZsoccerz\d+Z0000000   z will removedz,utils/xbox_public/confirm_delete_account.pngz0 find confirm delete, press left and cross cross)delete_keysdelete_failed_onlytry_counter)$r   r   r	   r   printr   just_find_stater   pstimesleepcrossrangeuprightdownget_screen_shot	has_imageospathjoinr   cv2imreadimwriteget_screen_textstrlowerstrip
startswithlenresearchgroupleftdelete_accounts)r   r0   r1   r2   Z	current_sZnnnZmnntZaccount_countimgZcrop_account_nameZaccount_nameZremoving_account_namemZdelete_resultr   r   r   rO   !   s    













	





z$ConsoleAccountsUtils.delete_accountsc              	      s  t | jd t| jd | j  td tdD ]}| j	  td q4| j
  td | j  | jjtjtdddd	st | jd
 d S | j  td g }g }tjjtd dtddB | jjdD ]F}t|jdk r||j d|jdd  q|t|j qt | jd| tdD ]}| j
  td | j  | jtjtd| jj ddrt | jd | j  td | j   qP| jtjtd| jj dd}| jtjtd| jj dd}t !d}z||"dd |"dd ks@|"dd |"dd krL|#d}n0|#|"dd d |"dd f|"d }W n, t$y   t | jdt%&  Y q6Y n0 |'d | d! t()d | d!t(j*}t(j+|d ddt(j,d"}t(-d#| d!| | jj.d#| d!d$d% / }	| j.d#| d!/  t | jd&|	 ||	 q6ttd'd(d)  fd*d+|D }
dBttt0d-d.d/t1jj| jjd2  g }g }g }g }tt|
D ]J}t|d t|
D ]0}|
| |
| r||
| |
| f qΐq|
D ]J}d0}|D ]*|r||f d1} q@q|s|| q|D ]*t3fd2d3|
D sX| qXt | jd4 |D ]D\}}t | jd5| d6|  t1jj4| jjdd7| d6| d8 qt | jd9 |D ]D\}}t | jd5| d6|  t1jj4| jjdd:| d6| d8 qt | jd; |D ]4}t | jd5|  t1jj4| jjd<d=| d8 q@t | jd> |D ]4}t | jd5|  t1jj4| jjdd?| d8 qt | jd@| t | jdA| d S )CNzcheck accounts started ...zchecking accountsr   r/   r    .utils/xbox_add_account/add_switch_selected.pngr%   r&   r'   can not find add or switchr!   )delete_console_reason )console    xboxsr.   zserver exists gamer tag: r$   r"   utils/z_controls/add_guest.pngz0check accounts , add guest button found , break.z_controls/select_left.pngz_controls/select_right.pngtop_leftr   bottom_right)r   r   r"   r"   zsearch gamertag error : 	user_namez_tmp.png)ZfxfyinterpolationZuser_name_2_z?tessedit_char_whitelist=0123456789abcdefghijklmnopqrstuvwxyz@#_)r)   zread user name : )linereturnc                 S   s>   |    }t|dkr.|d  d|d  S |r:|d S dS )Nr"   r   rX   r   rU   )rH   splitrJ   )r`   partsr   r   r   extract_tag   s    z=ConsoleAccountsUtils.check_accounts_func.<locals>.extract_tagc                    s   g | ]} |qS r   r   ).0r`   )rd   r   r   
<listcomp>       z<ConsoleAccountsUtils.check_accounts_func.<locals>.<listcomp>皙?)abra   c                 S   s   |    }|   }t|dkrjt|dkrj|d |d krDdS td |d |d  }|dk rjdS td |   |   }||kS )Nr"   r   Fr   r    )rG   rb   rJ   difflibSequenceMatcherratio)ri   rj   r(   Za_partsZb_partsZtag_similarityZ
similarityr   r   r   
is_similar   s    z<ConsoleAccountsUtils.check_accounts_func.<locals>.is_similarFTc                 3   s   | ]} |V  qd S )Nr   )re   tag2)rn   tag1r   r   	<genexpr>
  rg   z;ConsoleAccountsUtils.check_accounts_func.<locals>.<genexpr>zmatched gamer tagsz  - u    ≈ zmatched gamer tags - )rV   status_codedescriptionz(duplicate gamer tags in reading accountsz+duplicate gamer tags in reading accounts - z=gamer tags exists in reading accounts but not found in serverr   z@gamer tags exists in reading accounts but not found in server - z=gamer tags exists in server but not found in reading accountsz@gamer tags exists in server but not found in reading accounts - zread gamer tag zserver gamer tags )rh   )5r   r   r	   r   r   r5   r6   r7   r9   r;   r<   r   r=   r>   r?   r@   rA   r   r8   r   objectsfilterr   rV   rJ   name_in_consoleappendplatformreplacerF   circler   r   opengetcrop
ValueError	traceback
format_excsaverB   rC   IMREAD_GRAYSCALEresizeINTER_CUBICrD   rE   rG   boolr   deleteanycreate)r   iZreaded_gamertagZserver_exists_gamertagiieZselect_leftZselect_rightimageZcropped_imageZselected_crop_textZreaded_tagsZmatched_tags
duplicatesZnot_in_serverZnot_in_readedjro   matchedri   rj   dr   )rd   rn   rp   r   check_accounts_func   s   








"











z(ConsoleAccountsUtils.check_accounts_funcc           	   	      s  t  jd d}td}tj|}td  j	   j
tjtd jj ddrt  jd  j  td	 q& j
tjtd jj d
drBt  jd  j  td  j  tdD ]} j  td qt  jjdd  j  td  j  td  j  td	 q& j
tjtd jj ddr*t  jd  j  td  j  tdD ]} j  td qt  jj  j  td  j  td  j  td  j  td  j  td	 q& j
tjtd jj ddrt  jd t jddd td d} jj }z,|j}d |_|jdgd t  jd| W n   t  jdt   Y n0 |s.z<t!t"t#d$ }t%&|j'(|}t  jd|j'd| W n   t  jd Y n0 |r:td D ]} j   fd!d"td#D  td	 t |dd td	  j   j   j   j   j  td	  j  td	  j  td	 t  jd$  j
tjtd jj dds*t  jd%  q:t  jd& q< j	   j
tjtd jj ddrt  jd'  j)   j*  td( t+  n t  jd) t jd*d+d qʐq:q& j
tjtd jj d,dr
t  jd-  j  td	 q& j
tjtd jj d.dr< j  q& j
tjtd jj d/drt  jd0 t jd0 td1 t,d0q&t  jd2| |d3k r|d7 } j-  q&t  jd4 d S q&d S )5Nzstart link with originr   Asia/Tehranr   rZ   z&_controls/need_link_account_step_1.pngr%   zlink origin account step 1r!   z&_controls/need_link_account_step_2.pngzlink origin account step 2F   r    T)	has_emojiz&_controls/need_link_account_step_3.pngzlink origin account step 3   z(_controls/need_link_account_step_3_1.pngz-link origin step 3_1 , need verification codezwait for verification code)update_timei backup_code)update_fieldszbackup code is : zcant get back up code , error )	timezone_z)no back up code found , enter app code , z totp : zerror on get totpr   c                    s   g | ]} j  qS r   )r   square)re   iir   r   r   rf     rg   z<ConsoleAccountsUtils.link_origin_account.<locals>.<listcomp>   zbackup code enteredz5need link not seen again. stop try enter verificationz2seems verification not entered correct , try againz"wait until press verification code<   zverification entered , breakzverification doneFz&_controls/need_link_account_step_4.pngzlink origin account step 4z&_controls/need_link_account_step_5.pngz/_controls/need_link_account_need_reset_pass.pngzlink origin need reset password  z%link account step else , try again : r"   zlink origin account complete).r   r   pytztimezonedatetimenowr6   r7   r   r=   r>   r?   r@   rA   r   rx   r   r8   r9   r   r
   r]   optionr<   passwordr	   r   account_backup_codelastr   r   r   r   intr   r   	timestamppyotpZTOTPapp_codeatr;   rN   r   	Exceptionerrors)	r   Z	try_againlocal_tzZstart_time_4nmr   Zbackup_objectdb_timeiiiir   r   r   link_origin_account2  s>   







































6








z(ConsoleAccountsUtils.link_origin_accountrU   outlook.office365.comc                 C   sX  | j   td tdD ]}| j   td q| j   td | j  | jj	t
jtddddsxtd | j   td td	D ]L}| j   td | j  | jj	t
jtd
dddr| j    qqt| jd | jjt
jtddgd | jjt
jtddgddd}|rBt| jd| dS t| jd| td t| | td | j   td t| jd| | jjt
jtddgd t| | td | j   td | jjt
jtdt
jtdt
jtdt
jtdgdgd}	| jj	t
jtddddrXt| jd | j   td dS | jj	t
jtdddds| jj	t
jtddddrt| jd | j   td d S | jj	t
jtddddrt| jd! | j   td tdD ]}| j   td qd"S | j	t
jtddrvt| jd# | j   | j   | j   | j   td$ d%}
td&}tj|}d }d}d'}|	sd(}g }|
dk rHt  | j  |
d7 }
| j  | j	t
jtd)ds$| j	t
jtd*ds$| j	t
jtd+drt| jd, | j   tj|tjd$d- }td | j   td$ d%}
| j  | j	t
jtd.drt| jd/| td/| td0D ].}| j   td | j   td0 qd1S n| j	t
jtd2dr~t| jd3 | j   td0 td4D ]}| j   q2t| | tj|tjd$d- }td0 | j   n:| j	t
jtd5dr$t| jd6 d }td4D ]~}t|||d7}| d8d r
| d9|kr
t!"d:| d8}|r,|#d} q0n"td;| d9d<| td qq|d u rt| jd=| td>| td0D ].}| j   td | j   td0 qZd>S td?| | j   td$ | j   td$ tdD ]}| j   td qt$| t%| tj|}td$ | j   td0 d%}
n| j	t
jtddrZ| j   td d%}
n^| j	t
jtd@drt| jdA t&t
jtdBd}t| jdC| dD| dEd%   k rdFk rn n| j   ndG| dEd%   k rdHk rn n | j   td0 | j   nddI| dEd%   k r<dJk rtn n4| j   td | j   td0 | j   n
| j   d%}
n2| j	t
jtdKdrt| jdL | j   d%}
n| j	t
jtdMdrt| jdN | j   d%}
n| j	t
jtdOd
r.t| jdP| t'|d0k	r0dQS | j   td tdRD ]}| j   	qLt()t()t*j+t%t(,d%dS t%t(,d%dSt()t*j+ g}t%|dT | }t| |dUdV |-| td | j   tdW | j   tdW | j  | j	t
jtdOd
r&| j   nd%}
n| j	t
jtdXd
rft| jdY | j   d%}
nR| j	t
jtdZd
rt| jd[ |
rd\|v 
rt| jd]| n| j   td | j   td d%}
n| j	t
jtd^ds| j	t
jtd_drZt| jd` td$D ]}| j .  td q$| j   d%}
dU}da}n^| j	t
jtdbdrt| jdc | j /  td | j   td | j   d%}
n| j	t
jtdddrt| jde | j   td | j   d%}
n| j	t
jtdfdrZt| jdg | j   td | j   d%}
dU}da}n^| j	t
jtdhdrt| jdi | j   d%}
n&| j	t
jtdjdr t| jdk | j   td$ tdD ]}| j   td qtd qHn| j	t
jtdldrdt| jdm | j   td | j .  td | j   td$ nT| j	t
jtdndrt| jdo | jj01  | jj02  | j3||||||dpS |
d$kr.|dUu r.| j   td$ tdD ]}| j   td qtd | j4 r.t| jdq da}qHtd t| jdr qt| jds |S )tNr   r/   r    rR   r%   r&   r'   rS   r$   z*utils/xbox_add_account/add_new_account.pngzfind enter email state.z"utils/xbox_add_account/sign_in.pngzwho_are_u.png)excluded_errors_imagez4utils/xbox_add_account/another_person_make_space.pngF)r   	wait_timecheck_errorsztry to send account mail, need_more_spaceztry to send account password, z.utils/xbox_add_account/enter_your_password.pngz)utils/xbox_add_account/after_password.pngz0utils/xbox_add_account/account_already_added.pngz(utils/xbox_add_account/add_mail_help.pngz*utils/xbox_public/xbox_account_suspend.pngzaccount suspendr   Zsuspendz&utils/xbox_public/account_locked_3.pngz&utils/xbox_public/account_locked_4.pngzaccount lockedlockedzaccount already createdexistsz/help us protect your account , need add supportr!   r   r   unknownZafter_password_failedz'utils/xbox_add_account/double_check.pngz)utils/xbox_add_account/double_check_2.pngz6utils/xbox_add_account/finish_adding_security_info.pngzafter password 2_1 found)secondsz8utils/xbox_add_account/double_check_temperrory_error.pngz double check temperrory error : r"   zdouble check temperrory errorz+utils/xbox_add_account/your_other_email.pngz,whats your other email , enter support emailr   z2utils/xbox_add_account/enter_double_check_code.pngzenter double check code)	imap_user	imap_pass	imap_hostbodyr6   zSecurity code: (\d+)zlast email : z start time : zcan not get security code : zcan not get security codezsecurity code : z+utils/xbox_add_account/after_password_2.pngzafter password 2 foundz$utils/xbox_add_account/yes_im_in.pngz,after password 2 found yes im in position :    r[   i  i  i  i  r   z+utils/xbox_add_account/after_password_3.pngzafter password 3 foundz-utils/xbox_add_account/contact_preference.pngzafter contact preference foundz(utils/xbox_add_account/add_gamertage.pngz/need enter gamer tag found , tried until now : Zgamertag_problem   	   rX   T)initial_upper   z+utils/xbox_add_account/after_password_4.pngzafter password 4 foundz1utils/xbox_add_account/account_settings_found.pngz'account settings found in other consoler,   z?start account dont need to save from old settings, gamer tag : z5utils/xbox_add_account/signin_security_perference.pngz*utils/xbox_add_account/no_bariers_menu.pngzin security preferencesuccessz2utils/xbox_add_account/choose_background_color.pngzchoosing background colorz*utils/xbox_add_account/link_controller.pngzlink controllerz)utils/xbox_add_account/make_this_home.pngzmake this homez+utils/xbox_add_account/after_password_5.pngzafter password 5z2utils/xbox_add_account/account_compelete_error.pngz%account complete error message.finishz(utils/xbox_add_account/keep_in_touch.pngzlets keep in touchz1utils/xbox_add_account/too_many_account_added.pngz+too many account added , need reset console)support_emailsupport_passwordsupport_imap_hostz"account creation success in here 2zadd account waiting ...zAccount creation successful)5r   r5   r6   r7   r9   r;   r<   r   r=   r>   r?   r@   rA   r   r3   r8   r   r   wait_for_imager
   r   wait_for_imagesrz   r   r   r   r   r   refresh_from_db	timedeltar   r   r|   rK   rL   rM   r   rF   r   rJ   randomchoicestringascii_lettersrandintrw   rN   r:   console_login_utilsrestart_consolexboxs_go_to_appxboxs_add_new_userr4   )r   emailr   	gamer_tagr   r   r   r   r   Zafter_password_foundZcounter1r   
start_timeZlast_send_code_timeZaccount_addedZcreating_statusZtry_change_gamer_tagZntmZiitZsecurity_coder   Z
last_emailZsearch_security_codeZiinZyes_positionr   random_stringZnew_gamer_tagr   r   r   r     s   



































































&&

&








>











	



























z'ConsoleAccountsUtils.xboxs_add_new_userN)TFr   )rU   rU   r   )__name__
__module____qualname__r   rO   r   r   r   r   r   r   r   r      s   
g + N  r   )!r   rk   r?   r   rK   r   r6   r   rB   r   r   PILr   	django.dbr   django.db.modelsr   accounts.modelsr   r   futplus.settingsr   r   sbc.public_methodsr	   r
   r   r   r   utils.realy_public_methodsr   r   r   r   r   r   r   <module>   s$   