
    P1i1                     F    d dl Z d dlmZ d dlmZ d dlmZ  G d de      Zy)    N)BaseCommand)timezone)TongshuCalendarc                       e Zd ZdZd Zd Zy)Commandz8Test the TongshuCalendar model with different parametersc                 j   |j                  dt        d       |j                  dt        t        dd      d       |j                  d	t        d
       |j                  dt        d       |j                  dt        dd       |j                  dg ddd       |j                  dt        d       y )Nz--yearz:Year to generate calendar data for (default: current year))typehelpz--month      zBMonth to generate calendar data for (1-12, default: current month))r	   choicesr
   z--dayz#Specific day to display details forz--days-rangez7Range of days to display (format: start-end, e.g., 1-5)z--extra-days
   zBNumber of days to include before and after the month (default: 10))r	   defaultr
   z--format)fullsummary	days-onlyr   z Output format (default: summary))r   r   r
   z--outputz$File to write JSON output (optional))add_argumentintrangestr)selfparsers     S/home/cursorai/projects/iching/tongshu/management/commands/test_tongshu_calendar.pyadd_argumentszCommand.add_arguments
   s    M 	 	

 	!RLU	 	 	
 	6 	 	

 	J 	 	

 	U	 	 	
 	43	 	 	
 	7 	 	
    c                   2 |j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }	|;|9| j                  j                  | j                  j	                  d| d	             nf|rd
| nd}
|rd| nd}|rd| nd}|rd| nd}| j                  j                  | j                  j	                  d|
 d| | | d| d		             t        j                  |||      2|r|r|r	 t        t        |j                  d            \  }}|dk  s
|dkD  s||kD  r8| j                  j                  | j                  j                  d|              y 2\  }}}}}}}| j                  j                  | j                  j	                  d| d| d| d| d	             g d}| j                  j                  d       | j                  j                  d        |D ]  }|d!   }|j                  | d|d"d      s!t        |j                  d      d#         }||cxk  r|k  sJn M|\  }}}}}}}}|d!   } |d   dk(  }!d}"| j                  j                  | d$| d$|  d%|! d&|" d$|d#   ||d#      nd         y |r|r|r| d|d"d|d"}#d }$2\  }}}}}}}|D ]  }|d!   |#k(  s|}$ n |$r| j                  j                  | j                  j	                  d(|# d             |$\  }}}}}}}}| j                  j                  t        j                  |$d#d)t        *             | j                  j                  d+       | j                  j                  d,|        | j                  j                  d-|        | j                  j                  d.|dk(          | j                  j                  d/|d!    d0|d    d1|d#    d0|d2    d3|d4    d0|d5    d6       | j                  j                  d7|d!    d|d    d|d#    d8|d2   dk(          | j                  j                  d9|d!           | j                  j                  d:|d           | j                  j                  d;|d#   dk(          | j                  j                  d<|d2           | j                  j                  d=|        | j                  j                  d>|d!           | j                  j                  d?|d   dk(          g d}|d#   +| j                  j                  d@||d#       dA|d#    dB       |<d!|cxk  rt!        |      k  r(n y | j                  j                  dC||    dA| dB       y 2d4   r2d4   d!   d!   }%2d4   dD   d!   }&| j                  j                  | j                  j	                  dE|% d|&              t#        2fdF2d4   D              }'|'r4| j                  j                  | j                  j	                  dG             2d4   r|dHk(  r܉2d4   d!   }(| j                  j                  | j                  j	                  dI             | j                  j                  t        j                  |(d#d)t        *             | j                  j                  | j                  j	                  dJ             | j                  j                  dK       | j                  j                  dL       |dMk(  r2})n#|dNk(  r2d4   })n2\  }}}}}}}t!        |      }*dO| dP| }+dQ|d!    d0|d    dR|d#    d0|d2    d6	},g d}dS||    dA| dB}-| j                  j                  | j                  j	                  dT|+              | j                  j                  | j                  j	                  |,              | j                  j                  | j                  j	                  |-              | j                  j                  | j                  j	                  dU|*              | j                  j                  | j                  j	                  dV             t%        |d d2       D ]  \  }.}| j                  j                  | j                  j	                  dW|.dz    d             |\  }}}}}}}}| j                  j                  d,|        | j                  j                  d-|        | j                  j                  d.|dk(          | j                  j                  dX|d!    d0|d    dY|d#    d0|d2    dZ|d4    d0|d5    d6       | j                  j                  d7|d!    d|d    d|d#    d8|d2   dk(          | j                  j                  d9|d!    d[|d    d\|d2    dB       |d!   } |d   dk(  }/|d#   }0g d}|/r| j                  j                  d]|         |0| j                  j                  d@||0    dA|0 dB        |	sy 2})|	rmt'        |	d^d_`      5 }1t        j(                  |)|1d)d#t        a       d d d        | j                  j                  | j                  j	                  db|	              y |dHk7  r7| j                  j                  t        j                  |)d)d#t        a             y y # t        $ r7 | j                  j                  | j                  j                  d'             Y y w xY w# 1 sw Y   xY w)cNyearmonthday
days_range
extra_daysformatoutputz+Generating calendar for current month with z extra dayszyear zcurrent yearzmonth zcurrent monthz, day  z, days zGenerating calendar for z, z with )r   r   r!   -r      zInvalid days range: z
Solar terms for days z to z in /:)woodfireearthmetalwaterz.Date		Day	Solar Term	Is Solar Term Day	Elementz-----		---	----------	----------------	-------r   02d   	z		 z[Invalid days range format. Please use the format 'start-end' with numbers between 1 and 31.z
Detailed info for F)indentensure_asciir   z
Decoded values:z  Date: z  Day: z  Is today: z  Bazi: Year[,z] Month[   z] Day[      ]z	  Lunar: z, leap=z  Lunar formatted: z    Month: z    Is 3-char title: z	    Day: z  Jianchu: z  Solar term index: z  Has solar term: z  Solar element: z ()z  Month element: zDate range: c              3      K   | ]_  }|d    j                  d     d      xs? |d    j                  d     d      xr# t        |d    j                  d      d         dk   a yw)r   z-01z-02r%   r/   r7   N)
startswithr   split).0dcalendar_datas     r   	<genexpr>z!Command.handle.<locals>.<genexpr>   s       *A 1M!$4#5S!9: \1M!$4#5S!9:Zs1Q4::c?STCU?VYZ?Z\)s   A%A(z6Note: Date range includes January/early February datesr   z$
Compact format example (first day):z
Array format explanation:zwRoot array: [year, month, month_bazi[y_g,y_e,m_g,m_e], month_element_index, days[], prev[year,month], next[year,month]]zDays array: [date, day, isToday(1=true/0=false), bazi[yg,ye,mg,me,dg,de], lunar[day,month,year,isLeap], lunarFormatted[fullDate,month,isTitle3Char,day], jianchu, solar[termIndex,hasSolarTerm,elementIndex]]r   r   zYear: z	, Month: zMonth Bazi: Year[z	], Month[zMonth Element: 
zTotal days: z
Sample days (first 3):z
Day z
  Bazi: Y[z] M[z] D[z	 (month: z, day: z  Solar term: wzutf-8)encoding)r3   r2   r   z
Output written to )getstdoutwritestyleSUCCESSr   get_month_datamapr   r=   ERRORr<   
ValueErrorjsondumpsr   lenany	enumerateopendump)3r   argsoptionsr   r   r   r    r!   output_formatoutput_fileyear_str	month_strday_str	range_str	start_dayend_day
month_bazimonth_element_index	days_data
prev_month
next_monthelementsr?   date_strday_numdateis_todaybazilunarlunar_formattedjianchusolarsolar_term_indexis_solar_term_day	term_nametarget_datespecific_day
first_date	last_dateearly_dates
sample_dayoutput_data
total_days
month_info	bazi_infoelement_infoihas_solar_termsolar_element_indexfr@   s3                                                     @r   handlezCommand.handle2   s   {{6"G$kk% [[.
[[.
H-kk(+ <EMKKdjj003^_i^jju1vwx)-tf~>H,1&(I(+senG2<'*."IKKdjj003KH:UWXaWbcjbklukvv|  ~H  }I  IT  2U  V  W (66!
 %D$%(j.>.>s.C%D"	7 q=GbLI4GKK%%djj&6&69Mj\7Z&[\ cp_eZ)<iU_!!$**"4"47NykY]^e]ffjkpjqqrswrxxy5z"{|F!!"WX!!"VW"A tH#..$qs1/EF !(.."5a"89G G6w6`a]gxuowX]+08(,1!HM) %'	))TF"WIR@P?QQUVgUhhijsittv  NS  TU  NV  Nbw  AF  GH  AI  xJ  hj  wk  +l  m #"  5T!F!E#;aCy9KL _l[D%%8)ZQ[Q4;&#$L 
 !!$**"4"47KK=XY5Z"[\XdUgxuowPU!!$**\!RWad"ef!!"56!!HTF"34!!GG9"56!!LQ"@A!!M$q'!DG9HTRSWIUVW[\]W^V__efjklfmennoptuvpwoxxy"z{!!IeAhZqq
!E!H:WUZ[\U]abUbTc"de!!$78J7K"LM!!K0B/C"DE!!$9/!:LPQ:Q9R"ST!!Ioa.@-A"BC!!Ky"9:!!$8q
"CD!!$6uQx1}o"FG G8'KK%%(9(58:L9MRPUVWPXzYZ&[\ '2q<O7_RUV^R_7_  KK%%(9(CV:W9XXZ[nZoop&qr  &q)!,Q/J%a(,Q/IKKdjj00<
|4PY{1[\]   'q) K
 !!$**"4"47m"op  :&q)!,JKKdjj003XZ[KKdjjAE[^_` KKdjj001NOPKK  X  YKK  n  o F"'Kk)'*K _l[D%%8)ZQ[YJ!$y8J+JqM?!JqM?)T^_`TaSbbcdnopdqcrrstI CH,X6I-J,K2NaMbbcdLKKdjj002j\1BCDKKdjj00I;@AKKdjj00L>CDKKdjj00<
|1LMN KKdjj001KLM#IbqM23!!$**"4"4vacU!_"EF Y\UgxuowPU!!HTF"34!!GG9"56!!LQ"@A !!JtAwiqa	d1gYaPTUVPWyX\]abc]d\eefgklmgnfoop"qr !!IeAhZqq
!E!H:WUZ[\U]abUbTc"de!!$78J7K9UdefUgThhop  AB  qC  pD  DE  #F  G $)8 !&qQ&+Ah#F!KK%%7G6H&IJ&2KK%%(9(CV:W9XXZ[nZoop&qr5 3:  (K k39Q		+quQPST :KKdjj003G}1UVWi'KKdjj5QR\_`a (U  !!$**"2"2  4Q  #R  SN :9s-   >A(l, 'Cl, 8Al, m/,=m,+m,/m8N)__name__
__module____qualname__r
   r   r    r   r   r   r      s    ED&
PKbr   r   )rN   django.core.management.baser   django.utilsr   tongshu.modelsr   r   r   r   r   <module>r      s!     3 ! *vbk vbr   