-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #463 from onc-healthit/LANTERN-803-add-webscraper-…
…chntechsolns LANTERN-803: Add webscraper chntechsolns
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
endpointmanager/pkg/chplendpointquerier/chntechsolutionswebscraper.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package chplendpointquerier | ||
|
||
import ( | ||
"regexp" | ||
"strings" | ||
|
||
"github.com/PuerkitoBio/goquery" | ||
"github.com/onc-healthit/lantern-back-end/endpointmanager/pkg/helpers" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func ChntechsolutionsWebscraper(CHPLURL string, fileToWriteTo string) { | ||
|
||
var lanternEntryList []LanternEntry | ||
var endpointEntryList EndpointList | ||
var entry LanternEntry | ||
|
||
doc, err := helpers.ChromedpQueryEndpointList(CHPLURL, "") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
doc.Find("p").Each(func(index int, phtml *goquery.Selection) { | ||
phtml.Find("code").Each(func(index int, phtml *goquery.Selection) { | ||
urlString := strings.ReplaceAll(phtml.Text(), "\n", " ") | ||
pattern := `https[^\s]*metadata` | ||
re := regexp.MustCompile(pattern) | ||
match := re.FindString(urlString) | ||
if len(match) != 0 { | ||
match = strings.TrimSpace(match) | ||
entry.URL = strings.TrimSuffix(match, "/metadata") | ||
lanternEntryList = append(lanternEntryList, entry) | ||
endpointEntryList.Endpoints = lanternEntryList | ||
} | ||
|
||
}) | ||
}) | ||
|
||
err = WriteCHPLFile(endpointEntryList, fileToWriteTo) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters