
    ti/N                     |   d 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m	Z	 ddl
mZ ddlmZ ddlZej                  j!                  d e ee      j&                               ej                  j!                  dd        ej(                  d      Z ed      Zd	ed
efdZd	eded
efdZ	 dCdeded
ee   fdZdDdededed
efdZ	 	 dEdedededed
ef
dZ	 	 	 dFd	edededed
ef
dZe dk(  rG ejB                  ejD                  dd         ejF                  d!"      Z$e$jK                  d#d$d%&       e$jK                  d'dd()       e$jK                  d*d+d,-       e$jK                  d.dd/)       e$jM                         Z' ee'jP                  e'jR                  e'jT                  e'jV                  0      Z, e-d1e,d   d2    d3        e-d4e,d	            e-d5e,d   d6    d7        e-d8e,d9   d:d;        e-d<e,d           e,d   r e-d=e,d            e-d>e,d?            e-d@e,dA    dB       yy)Gu  
Genesis Gold Pipeline — Prospect Audit Pipeline
=================================================
The revenue weapon: scrape prospect's website → score it → generate a
superior version with their logo → deploy as live demo → generate spore URL.

Flow:
  1. Scrape prospect URL via Jina API
  2. Extract business name, services, phone, location
  3. Score their current site (mobile, speed, SEO, conversion)
  4. Generate a superior landing page via Gemini
  5. Inject voice widget (their business context)
  6. Deploy to Netlify as a live demo
  7. Generate spore URL for outreach
  8. Create PDF audit report

Usage:
    python prospect_audit.py --url https://example-plumber.com.au
    python prospect_audit.py --url https://example-plumber.com.au --deploy
    N)datetimetimezone)Path)Optionalz,/mnt/e/genesis-system/scripts/clone_pipelinezgold_pipeline.prospect_auditz2/mnt/e/genesis-system/scripts/gold_pipeline/auditsurlreturnc                    t         j                  d|         | dddg ddd}	 ddl} |j                  d      5 }|j	                  d|  d	d
d
d      }|j
                  dk\  rGt         j                  d|j
                   d       |j	                  | dddd      }|j                  }n|j                  }t        |      |d<   |dd |d<   t        j                  d|t        j                        }|r%|j                  d      j                         dd |d<   t        j                  d|      }|r|d   j                         |d<   dD ])  }	|	j                         |j                         v s$|	|d<    n t        j                  d |t        j                         }
|
rx|
d   }t        j"                  d!|      D cg c]M  }|j                         r;t        |j                               d"kD  r|j                         j                  d#      O c}dd$ |d%<   ddd       t         j                  d-|d    d.|d    d/|d    d0|d    d1	       |S c c}w # 1 sw Y   >xY w# t$        $ r}t         j'                  d&|        	 dd'lm}  ||       j,                  xs d}|j/                  d(d      j#                  d)      d   j/                  d*d+      j1                         |d<   n# t$        $ r d,|d<   Y nw xY wY d}~d}~ww xY w)2z
    Scrape a prospect's website via Jina API.
    Returns: {content, business_name, phone, services, location, raw_length}
    z
Scraping:  r   )r   contentbusiness_namephoneserviceslocation
raw_lengthNg      >@)timeoutzhttps://r.jina.ai/z
text/plaintrue)AcceptzX-With-Generated-Altz
X-No-Cache)headersi  zJina returned z, trying direct scrape...z<Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36ztext/html,application/xhtml+xml)z
User-Agentr   T)r   follow_redirectsr   i:  r   z^(?:Title:|#\s+)(.+)   P   r   zb(?:(?:\+61|0)\s*[2-9]\s*(?:\d\s*){7,8}|\b1[38]00\s*\d{3}\s*\d{3}\b|\b(?:0[2-9])\s*\d{4}\s*\d{4}\b)r   )Sydney	MelbourneBrisbanePerthAdelaidez
Gold CoastCairnsDarwin
TownsvillezSunshine Coast	Newcastle
WollongongCanberraHobartr   zQ(?:services?|we\s+(?:offer|provide|specialise)|our\s+services)[:\s]+(.+?)(?:\n|$)u   [,\n•\-\*·|]   u   •-*·   r   zScrape failed: )urlparsezwww..- Businessz	Scraped:  (z chars, phone=z, location=))loggerinfohttpxClientgetstatus_codewarningtextlenresearch	MULTILINEgroupstripfindalllower
IGNORECASEsplit	Exceptionerrorurllib.parser&   hostnamereplacetitle)r   resultr/   clientrespdirectrawmphonescityservice_matchesservices_textser&   hosts                   =/mnt/e/genesis-system/scripts/gold_pipeline/prospect_audit.pyscrape_prospectrS   /   s?   
 KK*SE"#FH1U\\$' <	6::$SE**,2"(  D 3&0@0@/AAZ[\&d"C &* $  kkii#&s8F<  #FUF9 		13EA*+''!**:*:*<Sb*A' ZZuF "()//"3wJ  ::<399;.)-F:& !jjdR]]O  / 2  XX&8-H&wwyS^a%7 GGIOOI.& 1	&z"q<	P KK)F?34Bvl7K6LN[abi[jZkkvw}  I  xJ  wK  KL  M  NM#&q<	 <	|  1qc*+	1-C=))/RD&*ll62&>&D&DS&I!&L&T&TUXZ]&^&d&d&fF?# 	1&0F?#	11sn   I D2I.AI:AI	II III 	L 'K; A!K"!K;"K30K;2K33K;;L r   c                    dddddddddddd|j                         | j                  d      rdndd<   t        j                  d|      }t	        dt        |      dz        d<   g d	}t        fd
|D              }t	        d|dz        d<   t        fddD              rdndd<   t        fddD              rdndd<   t        fddD              rdndd<   dv sdv rdndd<   dv rdv rdndd<   t	        dt        t        |      dz              d<   dv rdndd <   d!d!d!d"d"d#d"d#d#d"d$
}t        |j                               }t        t        fd%|j                         D              |z        d&<   S )'za
    Score a prospect's website on key metrics.
    Returns scores 0-100 for each dimension.
    r   )mobile_friendlyhas_phone_prominenthas_ctahas_sslhas_voice_agenthas_chat_widgethas_reviews
has_schemahas_meta_descriptioncontent_lengthoverallhttpsd   rX   z(?:\+61|0)\s*[2-9]   rV   )	zcall nowzget a quotezbook nowz
contact usz
free quotezrequest a quotezget startedzbook onlinezenquire nowc              3   ,   K   | ]  }|v sd   yw)r   N .0wcontent_lowers     rR   	<genexpr>zscore_site.<locals>.<genexpr>   s     ?!A,>A?s   	   rW   c              3   &   K   | ]  }|v  
 y wNrd   re   s     rR   ri   zscore_site.<locals>.<genexpr>          +E!1+=  +E   )zvoice agentzai receptionisttelnyxzvoice widgetrY   c              3   &   K   | ]  }|v  
 y wrl   rd   re   s     rR   ri   zscore_site.<locals>.<genexpr>   rm   rn   )zchat widgetz	live chatchatbotintercomdriftrZ   c              3   &   K   | ]  }|v  
 y wrl   rd   re   s     rR   ri   zscore_site.<locals>.<genexpr>   s       'AaqM'9  'Arn   )reviewtestimonialstarratingzgoogle reviewr[   z
schema.orgzjson-ldr\   metadescriptionr]   2   r^   viewport   rU      
      )
rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   c              3   4   K   | ]  \  }}|   |z    y wrl   rd   )rf   krg   scoress      rR   ri   zscore_site.<locals>.<genexpr>   s     !LDAq&)a-!Ls   r_   )r<   
startswithr6   r;   minr5   sumanyintvaluesrounditems)	r   r   phone_patterns	cta_words	cta_countweightstotal_weightrh   r   s	          @@rR   
score_siter      s      !F MMOM  #~~g6AF9 ZZ 5w?N$'S-@2-E$FF !QI?y??ICR0F9 (+  +E  HD  +E  (E  KLF'*  +E  HD  +E  (E  KLF $'  'AC  'A  $AC  GHF= #/-"?9P]C]3cdF< -3m,CYfHfSlnF!"  #3CL2,=(>?F (2]'BF ! !G w~~'(Lc!LGMMO!LL|[\F9M    gemini-2.5-flashscrape_datamodelc                     ddl m}m} | d   }| d   }| d   xs d}| d   rdj                  | d         nd	}d
| d| d    d| d   dd  d| d|xs d d| d| d} |||      }	|	r ||	      S y)z6Generate a superior version of the prospect's website.r   )_call_gemini_clean_htmlr   r   r   	Australiar   z, zSee contentz(You are rebuilding a better version of "z("'s website.
The current website is at: r   z=

Here is their ACTUAL content (scraped from their website):
r   Ni.  z(

BUSINESS DETAILS (extracted):
- Name: z

- Phone: zSee content abovez
- Location: z
- Services: u  

YOUR TASK: Create a DRAMATICALLY BETTER version of their website. This is being
used as a live demo to show the business owner what their site COULD look like.

REQUIREMENTS:
1. Use their ACTUAL business name, phone, services, and location
2. Make it mobile-first, fast-loading, and conversion-optimised
3. Use Tailwind CSS CDN + Google Fonts Inter
4. Include proper SEO meta tags and LocalBusiness schema
5. Add a sticky header with their phone number
6. Add clear CTAs ("Call Now", "Get a Free Quote")
7. Include a "Services" grid using their actual services
8. Add placeholder testimonials in their industry style
9. Include a contact section with their phone and a lead capture form
10. Use a professional colour scheme appropriate for their industry

CRITICAL: This must look like THEIR website, upgraded. Use their business name
prominently. This is a sales demo — it needs to be impressive enough that the
business owner says "I want THIS as my website."

DESIGN:
- Professional, modern, clean
- Mobile-first responsive
- Australian English spelling
- Click-to-call phone links
- Subtle CSS animations (fade-in hero, hover effects)
- Trust signals (years in business, licensed, insured — if mentioned in content)

VOICE WIDGET: Include a floating button (bottom-right) with this HTML:
<div id="voice-demo" style="position:fixed;bottom:24px;right:24px;z-index:9999">
  <a href="https://aiva.agileadapt.com/s/demo" target="_blank"
    style="display:flex;align-items:center;gap:8px;background:linear-gradient(135deg,#4f46e5,#7c3aed);
    color:white;text-decoration:none;padding:12px 20px;border-radius:50px;font-weight:600;
    box-shadow:0 4px 20px rgba(79,70,229,0.4);transition:all 0.3s;"
    onmouseover="this.style.transform='scale(1.05)'"
    onmouseout="this.style.transform='scale(1)'">
    🎙️ Talk to Your AI Receptionist
  </a>
</div>

FOOTER: Small text "Website demo powered by Sunaiva AI | agileadapt.com"

OUTPUT: Return ONLY the complete HTML starting with <!DOCTYPE html>. No markdown, no code blocks.r   )generate_siter   r   join)
r   r   r   r   bizr   r   r   promptrI   s
             rR   generate_superior_siter      s    
 8
o
&C E:&5+H5@5LtyyZ01R_H9# ?'./ 0 Y   !	 
 


&&	' (J J +b5eFn vU
+C
3r   r
   prospect_urltierreferral_codec                     | |d}|r||d<   t        j                  t        j                  |d      j	                               j                         j                  d      }d| S )z&Generate a spore URL for the prospect.)utr),:)
separators=zhttps://aiva.agileadapt.com/s/)base64urlsafe_b64encodejsondumpsencodedecoderstrip)r   r   r   payloadencodeds        rR   generate_spore_urlr   *  s`     t,G$&&

7z299;fhvvc{  ,G955r   r   demo_url	spore_urlc                    | d   }t        j                  t        j                        j	                  d      }d }dj                  g d| d| d| d    d	|d
    d ||d
          d ||d          d ||d          d ||d          d ||d          d ||d          d ||d          d ||d          d ||d          d ||d          d ||d          d       }|d   d!k(  r|d"z  }|d   d#k  r|d$z  }|d   d%k  r|d&z  }|d   d'k  r|d(z  }|d   d!k(  r|d)z  }|d   d!k(  r|d*z  }|d+z  }|r|d,| d-| d.z  }|r|d/| d-| d.z  }|d0|d
    d1z  }|S )2z2Generate a markdown audit report for the prospect.r   z%Y-%m-%dc                 \    | dz  }d|z
  }| dk\  rdn| dk\  rdnd}| dd|z   d	|z   d|  d
S )Nr   F   u   🟢(   u   🟡u   🔴r)   u   █u   ░/100rd   )scorefilledemptycolours       rR   barz"generate_audit_report.<locals>.barF  sO    "V B;erkFv56>*55=/5'FFr   r
   z# Website Audit Report: z

## Date: z	
## URL: r   z

---

### Overall Score: r_   z/100

zh

---

### Detailed Scores

| Metric | Score | Status |
|--------|-------|--------|
| Mobile Friendly | rU   z |
| Phone Visibility | rV   z |
| Call-to-Action | rW   z |
| SSL Certificate | rX   z |
| AI Voice Agent | rY   z |
| Chat Widget | rZ   z |
| Customer Reviews | r[   z |
| Schema Markup | r\   z |
| SEO Meta Tags | r]   z |
| Content Depth | r^   z |

---

### Key Findings

r   u   **No AI Voice Agent** — You're missing calls after hours and when you're on the job. An AI voice receptionist answers every call 24/7, capturing leads you're currently losing.

r{   u   **Phone Number Not Prominent** — Visitors can't easily find how to call you. Your phone number should be in the header, hero, and footer — always one tap away.

r   u   **Weak Calls-to-Action** — Your site doesn't clearly tell visitors what to do next. Strong CTAs like 'Get a Free Quote' and 'Call Now' dramatically increase conversions.

r   u{   **Not Mobile-Optimised** — Over 60% of your visitors are on phones. A non-responsive site is losing you jobs every day.

u   **No Visible Reviews** — Customer testimonials and Google reviews build trust instantly. Businesses with visible reviews convert 270% more visitors.

u   **No Schema Markup** — Google can't properly understand your business. LocalBusiness schema markup helps you appear in local search results and Google Maps.

z,---

### What Your Website Could Look Like

z%**See your upgraded website live:** [z](z)

z#**Talk to your AI receptionist:** [z;---

### Recommended Action

Your current website scores **u_  /100**. With our AI-powered upgrade, your site would score **90+/100** and include:

- ✅ 24/7 AI voice receptionist (answers every call)
- ✅ Mobile-first, lightning-fast design
- ✅ SEO-optimised with schema markup
- ✅ Clear calls-to-action that convert visitors to leads
- ✅ Professional design that builds instant trust
- ✅ Australian Privacy Act 2026 compliant

**Pricing starts at $397/month** — less than $13/day, and a fraction of what a human receptionist costs.

---

### About AgileAdapt

AgileAdapt provides AI-powered voice agents and websites for Australian businesses. Our patent-protected technology ensures every AI decision is auditable and compliant with the upcoming Privacy Act 2026 ADM reforms.

**Contact:** hello@agileadapt.com | [agileadapt.com](https://agileadapt.com)

*This audit was generated automatically by Genesis AI.*
)r   nowr   utcstrftimer   )r   r   r   r   r   r   r   reports           rR   generate_audit_reportr   ;  sE    o
&C
,,x||
$
-
-j
9CG ) #  /
 
		U	 9%&' VI    1234! 5!" &!6789#":#$ y)*+%$,%& 	*+,'&-'( 0123)(4)* V-./0+*1+, &/01-,2-. vl+,-/../0 v456710812 v./013223FB  A%  J  	J#$r)  |  	|i2  D  	D 2%  R  	Rm!  o  	olq   w  	w
  F
 9(2hZuUU7	{"YKuUU
   &i01 2	 F2 Mr   deployc                 @   t        j                          }| ddddddddddd}t        |       }||d<   |d   s+d|d	<   t        t        j                          |z
  d
      |d<   |S t        | |d         }||d<   t        j                  d|d    d       t        ||      }|r||d<   t        |      |d<   t        j                  dd|d   j                               j                  d      xs d}	t        |	z  }
|
j                  dd       |
dz  j                  |d       t        j                  d|
dz   dt        |       d       |r3	 ddlm}  ||d |	 !      }|r||d"<   t        j                  d#|        t'        | d%|&      }||d'<   t)        |||d"   |(      }||d)<   t        j                  dd|d   j                               j                  d      xs d}	t        |	z  d*z  }|j*                  j                  dd       |j                  |d       t-        |      |d+<   t        j                  d,|        d-|d	<   t        t        j                          |z
  d
      |d<   |S # t"        $ r#}t        j%                  d$|        Y d}~d}~ww xY w).z~
    Run the full prospect audit pipeline.

    Returns dict with: scrape_data, scores, html, demo_url, spore_url, report
    Nr   r
   pending)r   r   r   html
html_charsr   r   r   report_pathelapsed_secsstatusr   r   scrape_failedr   r$   r   r   zSite score: r_   r   r   r   r   z
[^a-z0-9]+r(   r   prospectT)parentsexist_okz
index.htmlzutf-8)encodingzSaved superior site: r+   z chars))deploy_to_netlifyzdemo-)	site_namer   zDemo deployed: zDeploy failed: r   )r   r   r   )r   r   r   r   r   zaudit_report.mdr   zAudit report saved: complete)timerS   r   r   r-   r.   r   r5   r6   subr<   r:   
OUTPUT_DIRmkdir
write_textdeployerr   r?   r3   r   r   parentstr)r   r   r   r   startrE   r   r   r   slug	audit_dirr   r   rP   r   r   r   s                    rR   	run_auditr     s    IIKEF "#&K'F=y!*x!&tyy{U':A!>~ [34FF8
KK,vi0167 "+U;Dv"4y| vvmS+o*F*L*L*NOUUVYZh^h%	t4	\	!--dW-E+I,D+ERD	{RYZ[ 66,TuTF^L)1F:&KK/( <=
 #3QmLI#F; #
#	F F8 66-k/&B&H&H&JKQQRUVdZdDt#&77KTD96G4,F=
KK&{m45!F8"499;#6:F>M7  64556s   2I1 1	J:JJ__main__z/%(asctime)s %(levelname)s %(name)s: %(message)sz%H:%M:%S)levelformatdatefmtzGenesis Prospect Audit Pipeline)rz   z--urlTzProspect website URL)requiredhelpz--modelzGemini model)defaultr   z--deploy
store_truezDeploy demo to Netlify)actionr   z
--referralzAgency referral code)r   r   r   r   z
=== AUDIT COMPLETE: r   z ===zURL: zScore: r_   r   zSuperior site: r   r   z charszSpore URL: zLive demo: zReport: r   zTime: r   rO   )r   )r   r
   )r
   r
   )r   Fr
   ).__doc__argparser   r   loggingr6   sysr   r   r   pathlibr   typingr   r/   pathinsertr   __file__r   	getLoggerr-   r   dictrS   r   r   r   r   r   boolr   __name__basicConfigINFOArgumentParserparseradd_argument
parse_argsargsr   r   r   referralrE   printrd   r   rR   <module>r     s  *     	 
  '    3tH~,,- . A B			9	:FG
[ [ [DEC E# E$ E\ $FFF c]FZ
6S 
6 
6 
6UX 
6( 	bbb b 	b
 	bV $	X	XX X 	X
 
X~ zGgll3dnxy$X$$1RSF
$5KL
	+=NS

<>VW
b7MNDHHjj{{mm	F 
"6-#8#I"J$
OP	E&-
!"	GF8$Y/0
56	OF<036
:;	K{+,
-.jF:./01	HVM*+
,-	F6.)*!
,-3 r   