+
    Ȱi{                     $   R t ^ RIt^ RIt^ RIt^ RIHt ^ RIHt ]! R4      t]R,          R,          t]P                  RRR7       R	^
R
. ROR. RORR/t
R tRR ltRR ltRR lt]R8X  d$   ]! RR^
RR7      t]'       d   ]! R] 24       R# R# R# )zW
PHT Discovery Engine
Finds new target companies for outreach

Created: March 11, 2026
N)Path)datetimez*/Users/max/.openclaw/workspace/postharvest
automationdataT)parentsexist_ok	min_roomsfruit_typescitrusregionsSouth Africa
ca_storagec                    \        4       p \        R,          \        R,          \        R,          .pV EF  pVP                  4       '       g   K  \        VRRR7      ;_uu_ 4       p\        P
                  ! V4      pV F  pVP                  R4      ;'       g,    VP                  R4      ;'       g    VP                  RR	4      pV'       g   KQ  VP                  4       P                  R
R	4      P                  RR	4      P                  RR	4      P                  R4      pV P                  V4       K  	  RRR4       EK  	  \        R\        V 4       R24       V #   + '       g   i     EK9  ; i)z4Load companies already in system to avoid duplicateszverified-scored-facilities.csvzSA-MASTER-LIST-400.csvzMASTER-LIST-FINAL.csvrutf-8encodingDomainWebsite http://https://www./Nu   ✓ Loaded z existing companies)set	WORKSPACEexistsopencsv
DictReadergetlowerreplacestripaddprintlen)existingmaster_filesfilefreaderrowdomains          D/Users/max/.openclaw/workspace/postharvest/automation/1_discovery.pyload_existing_companiesr/      s$   uH 	44,,++L ;;==dC'22a*!C WWX.]]#'')2D]]PXZ\H]Fv!'!7!7	2!F!N!Nz[]!^!f!fgmoq!r!x!xy|!} V, " 32  
KH&9
:;O 322s   %3EE2EA$EE,c                    \         R,          pVP                  4       '       g   \        R4       . # VP                  4       P	                  4       p\        RV  RV R24       . # )zg
Discover companies via Apollo API
Note: Free tier is limited, this is a placeholder for the structure
z.apollo-keyu7   ⚠ Apollo API key not found, skipping Apollo discoveryzApollo discovery for  z - API integration pending)r   r   r%   	read_textr#   )region
fruit_typelimitapollo_key_fileapi_keys   &&&  r.   discover_from_apollor8   5   sb      -/O!!##GH	'')//1G 
!&:,6P
QRI    c                   . p\        4       p\        \        P                  R4      4      pV EF  pVP                  P                  R4      '       d   K'   \        VRRR7      ;_uu_ 4       p\        P                  ! V4      pV EF  p	V	P                  R4      ;'       g+    V	P                  R4      ;'       g    V	P                  R4      p
V	P                  R	4      ;'       g    V	P                  R
4      pV	P                  R4      pV
'       d	   V'       g   K  VP                  4       P                  RR4      P                  RR4      P                  RR4      P                  R4      pW9   d   K  V '       d/   V'       d'   V P                  4       VP                  4       9  d   EK!  TP                  RT
RTRT;'       g    T RVRVP                  R\        P                  ! 4       P!                  4       /4       \#        V4      V8  g   EK   M	  RRR4       EK  	  VRV #   + '       g   i     EK  ; i  \$         d(   p\'        RTP                   RT 24        Rp?EK5  Rp?ii ; i)z8
Pull from existing CSVs that haven't been enriched yet
z*.csv.r   r   r   zCompany NameNameCompanyr   r   Countryr   r   r   r   r   company_namer-   countryr4   source_filediscovered_dateNu   ⚠ Error reading z: )r/   listr   globname
startswithr   r   r   r    r!   r"   r#   appendr   now	isoformatr&   	Exceptionr%   )r3   r4   r5   	companiesr'   source_filesr)   r*   r+   r,   r?   r-   r@   domain_cleanes   &&&            r.   discover_from_existing_listsrO   G   s    I&(H 	w/0L99$$#	dC'22a*!C#&77>#:#c#ccggfo#c#cQTQXQXYbQcL WWX.DD#'')2DF!ggi0G'v  $*<<>#9#9)R#H#P#PQ[]_#`#h#hioqs#t#z#z{~#L $/  'fllnGMMO.S $$& ,!7#4#4f$j%tyy)8<<>+C+C+E&  9~.; " 32 R VeI 322@  	&tyykA378	sn   H5+4H  H 9)H #*H H A H 7H ?>H >AH 
H H5 H2+H52H55I' I""I'c                   \        RV  RV 24       \        RV R24       \        RV 24       \        4       p. p\        R4       \        WV4      pVP                  V4       \        R\	        V4       R24       \	        V4      V8  dW   V\	        V4      ,
          p\        R	V R
24       \        WV4      pVP                  V4       \        R\	        V4       R24       V'       d   \        P                  ! 4       P                  R4      p	\        RV  RV RV	 R2,          p
\        V
RRRR7      ;_uu_ 4       p. ROp\        P                  ! WR7      pVP                  4        VP                  V4       RRR4       \        R4       \        R\	        V4       R24       \        RV
 24       \        V
4      # \        R4       R#   + '       g   i     LY; i)z
Main discovery function

Args:
    region: Target region
    fruit_type: Target fruit type
    limit: Number of companies to find
    test_mode: If True, only find 10 companies
u   
🔍 Starting discovery: z - z
   Limit: z
 companiesz   Test mode: u$   
1️⃣ Searching existing lists...z	   Found z new companiesu   
2️⃣ Searching Apollo for z more...z from Apolloz%Y%m%d_%H%M%Sdiscovered__z.csvwr   r   )newliner   )
fieldnamesNu   
✅ Discovery complete!z
   Found: z
   Saved: u   
⚠ No new companies found)r?   r-   r@   r4   rA   rB   )r%   r/   rO   extendr&   r8   r   rH   strftime
OUTPUT_DIRr   r   
DictWriterwriteheader	writerowsstr)r3   r4   r5   	test_moder'   rK   from_existing	remainingfrom_apollo	timestampoutput_filer*   rU   writers   &&&&          r.   run_discoveryrd   |   s    
'xs:,
?@	JugZ
()	N9+
&' '(H I 

120UKM]#	Ic-()
89 9~C	N*	/	{(CD*6yI%	#k*+<89 LLN++O<	 [*QykQU#VV+sBAAQnJ^^A=F Y'	 B 	)+
3y>**56
;-();,- BAs   ;=G		G	__main__)r3   r4   r5   r]   u   
📁 Output: )applesr
   pearskiwisbananas)USAr   	AustraliazNew ZealandCanadaUK)2   )
   )rj   rf   ro   T)__doc__r   jsonrequestspathlibr   r   r   rX   mkdirTARGET_CRITERIAr/   r8   rO   rd   __name__resultr%    r9   r.   <module>ry      s         =>	%.
 
    - DR$	2$3j3j z	F x()  r9   