a
    }h#                     @   s0  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 ejd e jdd e  d d	lmZmZ d d
lmZmZmZ d dlmZ d dlmZ edZG dd dZ e!dkr,e"dZ#e#dkre  $  ne#dkr$e  %  ne&d dS )    N)config)close_old_connections)Q)timezonez..DJANGO_SETTINGS_MODULEzfutplus.settings)	new_printset_sbc_status)ConsoleNewConsoleAccountFifaAccount)	SBCWorker)	SBCSolverzAsia/Tehranc                   @   s*   e Zd Zg Zdd Zdd Zd	ddZdS )
AddNewAccountConsolec           
         sX  t d td}|j  j}t fddtd|d D }dd tjj	|d	D }g }td|d D ]} j
|dd
j} j
|dd
j}||}	|	st d| d| d qhtjj	||	d rt d|  qh|t| j
|dd
j j
|dd
j j
|dd
j j
|dd
j j
|dd
j|	d qh|rBtj| t t| d d S )Nz.add accounts for console from file to databaseadd_new_account_to_console.xlsxc                 3   s   | ]} j |d djV  qdS )   rowcolumnN)cellvalue).0i	sheet_obj VC:\Users\Administrator\Downloads\futplus_django\accounts\add_new_account_to_console.py	<genexpr>&       z>AddNewAccountConsole.add_accounts_from_file.<locals>.<genexpr>   r   c                 S   s   i | ]}|j |qS r   name)r   cr   r   r   
<dictcomp>(   r   z?AddNewAccountConsole.add_accounts_from_file.<locals>.<dictcomp>)name__inr      z	Console 'z' not found! Skipping row .)	user_nameconsolezAccount already exists:             )r&   passwordsupport_emailsupport_passwordsupport_imap_host	gamer_tagr'   z accounts added successfully.)printopenpyxlload_workbookactivemax_rowsetranger	   objectsfilterr   r   getr
   existsappendbulk_createlen)
selfwb_objr5   Zconsole_namesZconsolesZnew_accountsrow_itemconsole_namer&   r'   r   r   r   add_accounts_from_file   s>    
 
z+AddNewAccountConsole.add_accounts_from_filec           
      C   s   t d td}|j}|j}g }td|d D ]L}|j|ddj}|j|ddj}tj	j
|d}|rr|j
|d}|| q0|rt }	|D ]}|	t|jdd	d
dO }	qtj	
|	  d S )Nz'remove accounts from database with filer   r   r   r   )r&   )console__nameidT)flat)id__in)r1   r2   r3   r4   r5   r7   r   r   r
   r8   r9   r<   r   values_listdelete)
r?   r@   r   r5   Zdelete_queriesrA   r&   rB   querycombined_queryr   r   r   remove_accounts_from_fileI   s"    
z.AddNewAccountConsole.remove_accounts_from_fileTc                 C   s\  t dd d}tjj|d }|s:td td td tjj|d }|sjtd| td td t	jj
d	d	d
|d	d\}}d	|_|  t|d t|j|j|j|j|jd	}t|d |j}d	|_tdD ]$}	ttjjtd dtddB tddB tddB |t tjdd d}
td|
 t|d|
 |
D ]}tdD ]P}| }|dkrl qn0td |j  t !d |j"  t !d qNt |_#z|$  t !d |j%dd t !d t|d|jd|j& |j'j(|j|j|j)|j*|j+|j,d}t-  |dkrB|| j.v rBt|d|d|j d |_&|d!v rT||_&nd|_&td"|j d# d}W nj t/y } zPtd$|j d% d&}t-  |0  d|_&t1|d' t1t23  |_4W Y d }~n
d }~0 0 |jg d(d) t !| q@q|0  d*|_5|  t|d+ |rXtd, |j6  t !d |j7  t !d& q$d S )-NCONSOLE_NAME)defaultr   zno console name found in .envzplease enterr   )r'   z6add one account for this console in system , log in : Fconsole_manage_accounts)is_done	has_errorrunning_platformfifa_accountmanual_loyalzAdd Account Bot StartedzAdding Accountsr   )
add_statusfailedunknownafter_password_failed
   )days)r'   create_time__gtezthis accounts need to add : r)   ps4_mainzgo to home first 3zstart add account , email z add status )emailr,   r0   r-   r.   r/   r;   z2already exists but two try , so make it success , z -- success)r^   r;   lockedrX   gamertag_problemneed_more_spacesuspendzCongrat . account z create successzaccount z  creation failed , sleep 100 secd   z 
 trace : 
 )rU   	add_erroradd_start_time)update_fieldsTzAdd Accounts Done.zApressing left and right to keep console alive after add accounts.)8r   r	   r8   r9   firstr1   inputexitr   r   get_or_create	must_donesaver   r   rE   r&   r,   platformr   public_movesset_account_suspendr7   listr
   r   r   	localtime	timedeltajust_find_stateps4_buttonspstimesleepcrossre   xboxs_go_to_appgo_to_staterU   console_accounts_utilsxboxs_add_new_userr0   r-   r.   r/   r   exists_accounts	Exceptionrefresh_from_dbstr	traceback
format_excrd   rP   rightleft)r?   
keep_aliverB   console_objectrS   
sbc_workercreated
sbc_solverrn   iieZaccounts_need_to_additemiiiecurrent_statrU   Zwait_secondser   r   r   coree   s    














0



zAddNewAccountConsole.coreN)T)__name__
__module____qualname__r}   rC   rL   r   r   r   r   r   r      s   +r   __main__z)want to add : 1 , want to remove : 2 ? : 12zinvalid input)'ossysrv   r   djangor2   pytzdecoupler   	django.dbr   django.db.modelsr   django.utilsr   pathr<   environ
setdefaultsetupsbc.public_methodsr   r   accounts.modelsr	   r
   r   
sbc.modelsr   sbc.sbc_solverr   local_tzr   r   rh   Zinput_numberrC   rL   r1   r   r   r   r   <module>   s8   
 '


