+
    /Χi'Y                        R t ^ RIt^ RIt^ RIt^ RIHtHtHt ^ RIHt ^ RI	H
t
HtHt ^ RIt^ RIt]P                  P!                  ^ ]! ]! ]4      P&                  4      4       ^ RI5 ]P*                  ! ]P,                  R]P.                  ! ]R,          4      ]P2                  ! 4       .R7       ]P4                  ! ]4      t^t^t. R-OtR	t R
t!^t"R R lt#R R lt$R R lt%R R lt&R R lt'R.R R llt(R R lt)R/R R llt*R R lt+R R lt,R R  lt-R! R" lt.R# R$ lt/R% R& lt0R' R( lt1R) R* lt2R+ t3]R,8X  d
   ]3! 4        R# R# )0aC  
Social Media Batch Scheduler - Pinterest, Instagram, Facebook
Runs Monday morning, schedules posts for all three platforms:
- Pinterest: 3 listings/day at 9 AM, 2 PM, 7 PM (21 pins/day)
- Instagram: 1 post/day at 12 PM noon (2 PM Pinterest listing)
- Facebook: 1 post/day at 10 AM (9 AM Pinterest listing) - weekdays only
N)datetimetimezone	timedelta)Path)OptionalListDict)*z)%(asctime)s - %(levelname)s - %(message)szsocial-batch.log)levelformathandlersz10:00z12:00c                $    V ^8  d   QhR\         /#    returndict)r   s   "Y/Users/tonyclaw/.openclaw/workspace/scripts/pinterest-automation/social_batch_schedule.py__annotate__r   +   s      T     c                 (    RR\          2R\        RR/# )zGet Publer API headersAuthorizationBearer-API Publer-Workspace-IdzContent-Typezapplication/json)PUBLER_API_KEYPUBLER_WORKSPACE_ID r   r   get_headersr   +   s'     	;~&672* r   c                $    V ^8  d   QhR\         /# r   r   )r   s   "r   r   r   4   s      t r   c                 4   \         P                  4       '       g3   \        P                  R\          24       \        P
                  ! ^4       \        \         R4      ;_uu_ 4       p \        P                  ! V 4      uuRRR4       #   + '       g   i     R# ; i)zLoad listings JSONzListings file not found: rN)	LISTINGS_JSONexistsloggererrorsysexitopenjsonload)fs    r   load_listingsr+   4   sY    !!0@A	mS	!	!Qyy| 
"	!	!	!s   %BB	c                $    V ^8  d   QhR\         /# )r   datar   )r   s   "r   r   r   >   s     % % %r   c                    \        \        R4      ;_uu_ 4       p\        P                  ! W^R7       RRR4       R#   + '       g   i     R# ; i)zSave listings JSONw)indentN)r'   r!   r(   dump)r-   r*   s   & r   save_listingsr2   >   s.    	mS	!	!Q		$!$ 
"	!	!	!s	   <A	c                F    V ^8  d   QhR\         R\        \        ,          /# r   listingr   )r   r   r   )r   s   "r   r   r   D   s       (4. r   c                  a V P                  RR4      P                  4       p. R
Op\        P                  4        Uu. uF0  pVP	                  4       '       g   K  VP
                  V9  g   K.  VNK2  	  pp. pVP                  4       P                  RR4      P                  RR4      P                  4        F/  p\        V4      ^8  g   K  VR9  g   K  VP                  V4       K1  	  VR,          pRp^ pV F^  p	V	P
                  P                  4       P                  RR4      P                  RR4      o\        V3R	 lV 4       4      p
W8  g   KZ  T
pT	pK`  	  V^8  d   V# R# u upi )z9Find archive folder matching a listing by title keywords.title ,- :N   NN_c              3   8   <"   T F  qS9   g   K  ^x  K  	  R# 5i)   Nr   ).0r/   folder_names   & r   	<genexpr>&find_archive_folder.<locals>.<genexpr>Y   s     ?{!;.>AA{s   
)listedrejectedzsource-pngszcleanup-20260210)	withfortheandsvgcutfilecricut
silhouette)getlowerARCHIVE_DIRiterdiris_dirnamereplacesplitlenappendsum)r5   r7   exclude_foldersr*   archive_folderstitle_wordsword
best_match
best_scorefolderscorerA   s   &          @r   find_archive_folderrb   D   sD   KK$**,EOO&&((a88: 	
&&7 	
(  
 K%%c2.66sC@FFHt9q=T)ttt$ I b/KJJ!kk'')11#s;CCCM?{??JJ " Q/s   E#E#,E#c                F    V ^8  d   QhR\         R\        \         ,          /# )r   r`   r   )r   list)r   s   "r   r   r   c   s      t T
 r   c                    . pV P                  R4       FV  pVP                  P                  4       \         Uu. uF  q3P                  4       NK  	  up9  g   KE  VP	                  V4       KX  	  \        V4      # u upi )z2Get all JPGs from folder, excluding whats-includedz*.jpg)globrT   rP   EXCLUDED_FILESrX   sorted)r`   imagesimges   &   r   get_images_to_postrl   c   s^    F{{7#88>>~#F~!GGI~#FFMM# $ &> $Gs   A9c                R    V ^8  d   QhR\         R\        R\        \         ,          /# )r   r-   	max_countr   )r   intr   )r   s   "r   r   r   l   s%     ! ! ! !d4j !r   c                   V P                  R. 4      p. pV F  p\        V4      V8  d    MVP                  RR4      '       g   K/  VP                  R4      '       d   KH  \        VP                  R. 4      4      p\        VP                  R. 4      4      p\        V4      pV'       g   K  \	        V4      pV U	u. uF*  qP
                  V9  g   K  V	P
                  V9  g   K(  V	NK,  	  p
p	V
'       g   K  VP                  V4       K  	  V F  p\        V4      V8  d    V# VP                  RR4      '       d   K0  VP                  R4      '       d   KI  \        VP                  R. 4      4      p\        VP                  R. 4      4      p\        V4      pV'       g   K  \	        V4      pV U	u. uF*  qP
                  V9  g   K  V	P
                  V9  g   K(  V	NK,  	  p
p	V
'       g   K  VP                  V4       K  	  V# u up	i u up	i )z7Get unposted listings, priority first, up to max_count.listingspriorityFdelistedposted_imagesscheduled_images)rO   rW   setrb   rl   rT   rX   )r-   rn   rq   unpostedr5   posted	scheduledr`   ri   rj   	remainings   &&         r   get_unposted_listingsr{   l   s   xx
B'HH x=I%;;z5))'++j2I2I_b9:FGKK(:B?@I(1Fv+F3,2kFShhf6LSQTQYQYajQjSSF	k9OOG,  x=I% O {{:u--gkk*6M6M_b9:FGKK(:B?@I(1Fv+F3,2kFShhf6LSQTQYQYajQjSSF	k9OOG,  O% l ls$   9HH#H/HHHc                F    V ^8  d   QhR\         R\        \        ,          /# )r   
image_pathr   )r   r   r   )r   s   "r   r   r      s      T htn r   c                T   RR\          2R\        /p \        V R4      ;_uu_ 4       pRV P                  VR3/p\        P
                  ! \         R2VVRR	R
R/R7      pVP                  4        VP                  4       pRVP                  R4      ;'       g    VP                  R4      RVP                  RR4      RVP                  RR4      /uuRRR4       #   + '       g   i     R# ; i  \         d1   p\        P                  RT P                   RT 24        Rp?R# Rp?ii ; i)z%Upload image to Publer Media Library.r   r   r   rbrL   z
image/jpegz/mediadirect_uploadtrue
in_libraryfalse)headersfilesr-   id_idpathr8   	thumbnailNzFailed to upload media z: )r   r   r'   rT   requestspostPUBLER_API_BASEraise_for_statusr(   rO   	Exceptionr#   r$   )r}   r   r*   r   respresultrk   s   &      r   upload_mediar      s    	;~&672G
*d##qjooq,?@E=="#6*%v|WE	D !!#YY[Ffjj&;;&**U*;

62.VZZR8 $###  .z.?r!EFs5   C, B&C
C, C)	#C, )C, ,D'7%D""D'c                R    V ^8  d   QhR\         R\        R\        \        ,          /# )r   job_idmax_attemptsr   )strro   r   r   )r   s   "r   r   r      s%      C s HTN r   c                |   \        4       p\        V4       F  p \        P                  ! \         RV  2VR7      pVP                  4        VP                  4       p\        V\        4      '       d   V'       d
   V^ ,          M/ p\        V\        4      '       d   VP                  R4      MRpVR9   d   Vu # VR8X  d   \        P                  RV 24        R# \        P                  ! ^4       K  	  R#   \         d;   p\        P                  RT 24       \        P                  ! ^4        Rp?EK   Rp?ii ; i)	z*Poll job status until completed or failed.z/job_status/)r   statusNfailedzJob failed: zError polling job status: )	completedcomplete)r   ranger   rO   r   r   r(   
isinstancerd   r   r#   r$   timesleepr   )r   r   r   attemptr   r   r   rk   s   &&      r   poll_job_statusr      s    mG&	<<"#<x8D !!#YY[F&$''&,"-7-E-EVZZ)4F228#|F845JJqM' '0 	  	LL5aS9:JJqMM	s*   AC69<C68C6C66D;.D66D;c                0    V ^8  d   QhR\         R\        /# r4   r   r   )r   s   "r   r   r      s      D S r   c                    V P                  RR4      pV P                  RR4      p\        P                  VR4      pRRRRRR	R
R/pRV RVP                  W4R,          4       R2pVP                  4       # )z7Generate Pinterest-optimized description (SEO keywords)r7   r8   category	christianmilitaryz7#USMC #MarineCorps #VeteranMade #MilitaryLife #SemperFi	patrioticz;#USA #PatrioticDecor #AmericanMade #4thOfJuly #RedWhiteBluez@#ChristianArt #FaithBased #ChurchDecor #ReformedTheology #Easteroutdoorz=#HuntingLife #WildlifeArt #CabinDecor #OutdoorLife #NatureArtu   ✨ uM   ✨

Perfect for Cricut, Silhouette, laser cutters & vinyl cutting machines!

🎨 Instant digital download includes:
• SVG file (vector, infinitely scalable)
• PNG file (high resolution, transparent background)

💡 Create stunning:
• T-shirts & apparel
• Tumblers & mugs  
• Wall art & signs
• Car decals & stickers

z* #SVGCutFile #DigitalDownload #CricutMade
rO   CATEGORY_TO_NICHEstrip)r5   r7   r   niche
niche_tagsdescriptions   &     r   generate_pinterest_descriptionr      s    KK$E{{:r*H!!(K8E 	MRWR	J 5' " +./ 0 1K  r   c                0    V ^8  d   QhR\         R\        /# r4   r   )r   s   "r   r   r      s            r   c                2   V P                  RR4      pV P                  RR4      p\        P                  VR4      pRRRRRR	R
R/pRRRRRRR
R/pVP                  W4R,          4      pVP                  W5R,          4      pV RV RV 2pVP                  4       # )z0Generate Instagram caption (hashtags + engaging)r7   r8   r   r   r   u   Semper Fi. 🦅r   u   Land of the free. 🇺🇸u   To God be the glory. ✝️r   u   Where the wild things are. 🦌z#USMC #MarineCorps #Veteran #MilitaryLife #SemperFi #Marines #MilitaryWife #MilitaryFamily #ProudMarine #CricutMade #SVGFiles #DigitalDownload #VeteranOwnedzx#USA #America #Patriotic #RedWhiteBlue #AmericanMade #4thOfJuly #ProudAmerican #CricutMade #SVGFiles #DIY #SmallBusinesszy#Christian #Faith #Jesus #Bible #ChurchDecor #Easter #Reformed #Scripture #CricutMade #SVGFiles #ChristianArt #FaithBasedzr#Hunting #Wildlife #Outdoors #Nature #Deer #CabinLife #CountryLiving #CricutMade #SVGFiles #OutdoorLife #NatureArt

uA   

SVG cut file for Cricut, Silhouette & more.
Link in bio! 🔗

r   )	r5   r7   r   r   openershashtagsopenertagscaptions	   &        r   generate_instagram_captionr      s    KK$E{{:r*H!!(K8E 	%124	G 	  s  P  Q  H	H [[ 45F<<45D(  
 
G ==?r   c                0    V ^8  d   QhR\         R\        /# r4   r   )r   s   "r   r   r     s      t  r   c                    V P                  RR4      pV P                  RR4      p\        P                  VR4      pRRRRRR	R
R/pVP                  W4R,          4      pV RV R2pVP                  4       # )z>Generate Facebook caption (conversational, engagement-focused)r7   r8   r   r   r   u3   Know a Marine who'd love this? Tag them below! 🦅r   uP   Perfect for your next patriotic project! What would you make with this? 🇺🇸uL   This would look beautiful in a church or home. Who needs this design? ✝️r   uE   Calling all outdoor lovers! What project would you use this for? 🦌r   u   

✨ Instant digital download
✨ SVG, PNG & more included
✨ Works with Cricut, Silhouette & laser cutters

Shop link in comments! 👇r   )r5   r7   r   r   hookshookr   s   &      r   generate_facebook_captionr     s    KK$E{{:r*H!!(K8E 	IgcZ	E 99U+./D'  G ==?r   c                l    V ^8  d   QhR\         R\        R\        R\        R\        R\        R\        /# )r   
media_infor7   r   linkboard_idscheduled_atr   r   r   bool)r   s   "r   r   r   *  sW     D DDD D 	D
 D D 
Dr   c                   \        4       pRRRRRRRRR	VR
,          RVR,          RVRRV R,          RRRV P                  RR4      RV P                  RR4      /.//RR\        RVRV/././/p \        P                  ! \
         R2VVR7      pVP                  4        VP                  4       p	V	P                  R4      p
V
'       dZ   \        V
4      pV'       dG   VP                  R/ 4      P                  R/ 4      pV'       g   R# \        P                  RV 24       R# R#   \         d$   p\        P                  RT 24        Rp?R# Rp?ii ; i) z/Schedule a Pinterest pin for future publishing.bulkstatery   postsnetworks	pinteresttypephototext:Ni  Nr7   :Nd   Nurlmediar   r   r8   r   accountsalbum_idr   /posts/scheduler   r(   r   payloadfailuresTzJob completed with failures: FzFailed to schedule pin: N)r   rO   PINTEREST_ACCOUNT_IDr   r   r   r   r(   r   r#   r$   r   )r   r7   r   r   r   r   r   r   r   r   r   finalr   rk   s   &&&&&&        r   schedule_pinterest_pinr   *  sv    mG 	[#"G"K$5#U4[!4#$(*T*:$*G$*JNN62,F$/R1P	!"&&!   "6&*L!#
GB}}/

 	H%#F+E 99Y377
BGLL#@
!KL  /s34s   .BD" D" "E-EEc                H    V ^8  d   QhR\         R\        R\        R\        /# )r   r   r   r   r   r   )r   s   "r   r   r   q  s0     > >>> > 
	>r   c                   \        4       pRRRRRRRRR	VR
,          RRV R,          RRRV P                  RR4      RV P                  RR4      /.//RR\        RV/././/p \        P                  ! \
         R2VVR7      pVP                  4        VP                  4       pVP                  R4      pV'       dZ   \        V4      pV'       dG   VP                  R/ 4      P                  R/ 4      p	V	'       g   R# \        P                  RV	 24       R# R#   \         d$   p
\        P                  RT
 24        Rp
?
R# Rp
?
ii ; i)zSchedule an Instagram post.r   r   ry   r   r   	instagramr   r   r   :Ni  Nr   r   r   r8   r   r   r   r   r   r   r   r   Tz'Instagram job completed with failures: Fz#Failed to schedule Instagram post: N)r   rO   INSTAGRAM_ACCOUNT_IDr   r   r   r   r(   r   r#   r$   r   )r   r   r   r   r   r   r   r   r   r   rk   s   &&&        r   schedule_instagram_postr   q  sa    mG 	[#"G"GEN#$(*T*:$*G$*JNN62,F$/R1P	!"&&!  "6*L!
G<}}/

 	H%#F+E 99Y377
BGLL#J8*!UV  :1#>?s   !BD 9D E D>>Ec          
      T    V ^8  d   QhR\         R\        R\        R\        R\        /# )r   r   r   r   r   r   r   )r   s   "r   r   r     s:     ? ??? ? 	?
 
?r   c                   \        4       pRRRRRRRRR	V R
V 2RRV R,          RRRV P                  RR4      RV P                  RR4      /.//RR\        RV/././/p \        P                  ! \
         R2VVR7      pVP                  4        VP                  4       pVP                  R4      pV'       dZ   \        V4      p	V	'       dG   V	P                  R/ 4      P                  R/ 4      p
V
'       g   R# \        P                  RV
 24       R# R#   \         d$   p\        P                  RT 24        Rp?R# Rp?ii ; i)zSchedule a Facebook page post.r   r   ry   r   r   facebookr   r   r   u   

🛒 Shop: r   r   r   r8   r   r   r   r   r   r   r   r   Tz&Facebook job completed with failures: Fz"Failed to schedule Facebook post: N)r   rO   FACEBOOK_ACCOUNT_IDr   r   r   r   r(   r   r#   r$   r   )r   r   r   r   r   r   r   r   r   r   r   rk   s   &&&&        r   schedule_facebook_postr     sh    mG 	[""G"witf$E#$(*T*:$*G$*JNN62,F$/R1P	!"&%!  "5*L!
G<}}/

 	H%#F+E 99Y377
BGLL#I(!TU  9!=>s   BD 7D ED<<Ec                0    V ^8  d   QhR\         R\        /# )r   dater   )r   r   )r   s   "r   r   r     s      X $ r   c                (    V P                  4       ^8  # )z+Check if date is a weekday (Mon=0 to Fri=4))weekday)r   s   &r   
is_weekdayr     s    <<>Ar   c                v    V ^8  d   QhR\         R\        R\        R\         R\        \        \        3,          /# )r   r5   day_date
slot_indexr-   r   )r   r   ro   r   r   )r   s   "r   r   r     sI     V VVV V 	V
 
#s(^Vr   c           	     >	   R^ R^ R^ /p\        V 4      pV'       g2   \        P                  RV P                  RR4      R,           24       V# \	        V P                  R. 4      4      p\	        V P                  R	. 4      4      p\        V4      pV U	u. uF*  qP                  V9  g   K  V	P                  V9  g   K(  V	NK,  	  p
p	V
'       g   V# V
^ ,          p\        V4      pV'       g   V# V P                  R
4      ;'       g    \        V 4      p\        V 4      p\        V 4      pV P                  RR4      p\        P                  V\        R,          4      p\        V,          p\        \        VP                  R4      4      w  ppVP!                  VV^ ^ R7      pVP#                  R4      R,           p\        P%                  RV P                  RR4      R,           RV 24       \'        WP                  RR4      VV P                  RR4      VV4      '       d?   ^VR&   R	V 9  d   . V R	&   V R	,          P)                  VP                  4       \+        V4       V^8X  d   \        \        \,        P                  R4      4      w  ppVP!                  VV^ ^ R7      pVP#                  R4      R,           p\        P%                  RV P                  RR4      R,           R\,         24       \/        WV4      '       d   ^VR&   V^ 8X  d   \1        V4      '       d   \        \        \2        P                  R4      4      w  ppVP!                  VV^ ^ R7      pVP#                  R4      R,           p\        P%                  RV P                  RR4      R,           R\2         24       \5        WV P                  RR4      V4      '       d   ^VR&   \1        V4      '       g   V^ 8X  d   \        \        \,        P                  R4      4      w  ppVP!                  VV^ ^ R7      pVP#                  R4      R,           p\        P%                  RV P                  RR4      R,           R\,         24       \/        WV4      '       d   ^VR&   \6        P8                  ! ^4       V# u up	i )zDSchedule a listing across all platforms. Returns counts by platform.r   r   r   zNo archive folder found for: r7   Unknown:N2   Nrt   ru   pinterest_descriptionr   r8   zEaster SVGs:hourminutesecondmicrosecondz%Y-%m-%dT%H:%M:%Sz-08:00zScheduling Pinterest: :N(   Nz at r   zScheduling Instagram: zScheduling Facebook: zScheduling Weekend Instagram: )rb   r#   warningrO   rv   rl   rT   r   r   r   r   PINTEREST_BOARD_IDSPINTEREST_TIME_SLOTSmapro   rV   rU   strftimeinfor   rX   r2   INSTAGRAM_TIME_SLOTr   r   FACEBOOK_TIME_SLOTr   r   r   )r5   r   r   r-   resultsr`   rx   ry   ri   rj   rz   first_imager   pinterest_descinstagram_captionfacebook_captionr   r   pinterest_timer   r   pinterest_scheduledpinterest_atig_hour	ig_minuteig_scheduledig_atfb_hour	fb_minutefb_scheduledfb_ats   &&&&                           r   schedule_listing_all_platformsr    s5    A{Az1=G )F6w{{7I7VWZ7[6\]^ _b12FGKK 2B78I'F &_((&*@SXXU^E^I_ A,K k*J [[!89dd=[\c=dN27;09{{:r*H"&&x1D]1STH **5NsN0056LD&"**VA[\*]&//0CDxOL KK(Wb)A#)F(GtNK[\]j++gr*BN%kk%4hN N W,*,G&'"#**;+;+;<d Q &9&?&?&DE''WYq^_'`%%&9:XE,W[["-Ec-J,K4PcOdef":%HH#$GK  Q:h// &8&>&>s&CD''WYq^_'`%%&9:XE+GKK,DS,I+J$OaNbcd!*ESU@VX]^^"#GJ hJ!O &9&?&?&DE''WYq^_'`%%&9:XE4W[["5Mc5R4SSWXkWlmn":%HH#$GK JJqMNI `s   R)R<Rc            	        \         P                  R4       \         P                  R4       \         P                  R4       \         P                  R4       \        4       p \        \        ,          p\        W4      pV'       g#   \         P                  R4       \        R4       R# \         P                  R\        V4       R24       \        P                  ! 4       P                  ^ ^ ^ ^ R7      pR	^ R
^ R^ /p^ p\        \        4       F  pV\        V4      8  d    MV\        VR7      ,           pVP                  R4      pVP                  R4      p	\         P                  RV RV	 R24       \        V4      '       d   ^M^p
\        V
4       F`  pV\        V4      8  d    K  W%,          p\        WW4      pVP!                  4        F  w  rWN;;,          V,          uu&   K  	  V^,          pKb  	  K  	  \         P                  R4       \         P                  RV R24       \         P                  RVR	,           R24       \         P                  RVR
,           R24       \         P                  RVR,           R24       \         P                  R4       \        RVR	,           RVR
,           RVR,           24       R# )z6Main entry point - schedule all platforms for the weekz7Social Media Batch Scheduler - Starting Weekly Schedulez)Platforms: Pinterest, Instagram, FacebookzNo unposted listings foundALL_SCHEDULEDNzFound z listings to scheduler   r   r   r   )daysz%Az%Y-%m-%dz
--- z, z ---zCOMPLETE: Scheduled z	 listingsz  Pinterest: z postsz  Instagram: z  Facebook:  zSUCCESS: Pinterest=z, Instagram=z, Facebook=z<============================================================)r#   r   r+   LISTINGS_PER_DAYDAYS_TO_SCHEDULEr{   printrW   r   nowrU   r   r   r   r   r  items)r-   max_listingsrq   
start_datetotalslisting_indexdayr   weekday_nameday_strslots_todayslot_idxr5   r   platformcounts                   r   mainr#  R  sL   
KK
KKIJ
KK;<
KK?D $&66L$T8H01o
KK&X'<=> ''QqPQ'RJ1k1j!<FM%&CM)	s 33((.##J/f\N"WIT:; &h//aQk*HH--G4WWG#*==? E)  $3 QM + '2 KK
KK&}oY?@
KK-{ 34F;<
KK-{ 34F;<
KK-z 236:;
KK	{ 34LAT@UU`aghras`t
uvr   __main__)z09:00z14:00z19:00)#   )   )4__doc__r(   r%   r   r   r   r   pathlibr   typingr   r   r   loggingr   r   insertr   __file__parentconfigbasicConfigINFOFileHandlerLOG_DIRStreamHandler	getLogger__name__r#   r  r  r   r   r   MAX_PINS_PER_DAYr   r+   r2   rb   rl   r{   r   r   r   r   r   r   r   r   r   r  r#  r   r   r   <module>r7     s;    
  2 2  ' '   3tH~,,- .    
,,6G&889 
		8	$   2    %>!H8>@ F8DN>B?D
Vr:wz zF r   