-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRun-WebsiteDiscovery.ps1
More file actions
61 lines (51 loc) · 1.76 KB
/
Copy pathRun-WebsiteDiscovery.ps1
File metadata and controls
61 lines (51 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
param(
[string]$SourceUrl = $env:WEB_DISCOVERY_SOURCE_URL,
[string]$FeedPath = $env:WEB_DISCOVERY_FEED_PATH,
[int]$MaxPages = 5,
[bool]$OpenApp = $true
)
$ErrorActionPreference = "Stop"
$ProjectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $ProjectRoot
if (!(Test-Path ".env")) {
Copy-Item ".env.example" ".env"
}
Get-Content -LiteralPath ".env" | ForEach-Object {
if ($_ -match '^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=(.*)$') {
[Environment]::SetEnvironmentVariable($matches[1], $matches[2], "Process")
}
}
if ([string]::IsNullOrWhiteSpace($SourceUrl)) {
$SourceUrl = "https://www.compassultra.com/"
}
if ([string]::IsNullOrWhiteSpace($FeedPath)) {
$FeedPath = "C:\Users\enter\Compass-Ultra\app\public\crawler-feed.json"
}
$DiscoverArgs = @("scripts\discover_websites.py", "--source-url", $SourceUrl)
if (Test-Path $FeedPath) {
$DiscoverArgs += @("--feed-file", $FeedPath)
}
.\.venv\Scripts\python.exe @DiscoverArgs
.\.venv\Scripts\python.exe scripts\crawl_websites_to_snowflake.py --urls-file targets\discovered_websites.txt --max-pages $MaxPages
$env:DBT_PROFILES_DIR = $ProjectRoot
.\.venv\Scripts\dbt.exe build --select stg_web_pages fct_website_signals mart_prospect_accounts mart_website_query_index
if ($OpenApp) {
$AppUrl = "http://localhost:8501"
$AppIsRunning = $false
try {
$TcpClient = [System.Net.Sockets.TcpClient]::new()
$Connect = $TcpClient.BeginConnect("127.0.0.1", 8501, $null, $null)
$AppIsRunning = $Connect.AsyncWaitHandle.WaitOne(500, $false)
if ($AppIsRunning) {
$TcpClient.EndConnect($Connect)
}
$TcpClient.Close()
} catch {
$AppIsRunning = $false
}
if ($AppIsRunning) {
Start-Process $AppUrl
} else {
.\.venv\Scripts\python.exe -m streamlit run app\streamlit_app.py
}
}