Skip to content

Commit

Permalink
feat: appended schema with accepting_appointments
Browse files Browse the repository at this point in the history
  • Loading branch information
brittonhayes committed Aug 21, 2023
1 parent 2811521 commit e04220f
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 43 deletions.
36 changes: 19 additions & 17 deletions api/therapist.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
package api

type Therapist struct {
ID int `bun:"id,pk,autoincrement" json:"id"`
Title string `json:"title"`
Credentials string `json:"credentials"`
Verified string `json:"verified"`
Statement string `json:"statement"`
Phone string `json:"phone"`
Location string `json:"location"`
Link string `json:"link"`
ID int `bun:"id,pk,autoincrement" json:"id"`
Title string `json:"title"`
AcceptingAppointments string `json:"accepting_appointments"`
Credentials string `json:"credentials"`
Verified string `json:"verified"`
Statement string `json:"statement"`
Phone string `json:"phone"`
Location string `json:"location"`
Link string `json:"link"`
}

type GetTherapistParams struct {
Title *string `json:"title"`
Credentials *string `json:"credentials"`
Verified *string `json:"verified"`
Statement *string `json:"statement"`
Phone *string `json:"phone"`
Location *string `json:"location"`
Link *string `json:"link"`
Limit *int `json:"limit"`
Offset *int `json:"offset"`
Title *string `json:"title"`
Credentials *string `json:"credentials"`
AcceptingAppointments *bool `json:"accepting_appointments"`
Verified *string `json:"verified"`
Statement *string `json:"statement"`
Phone *string `json:"phone"`
Location *string `json:"location"`
Link *string `json:"link"`
Limit *int `json:"limit"`
Offset *int `json:"offset"`
}
15 changes: 11 additions & 4 deletions cmd/psych/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ func main() {
Value: "",
Category: "Scraping",
},
&cli.StringFlag{
Name: "insurance",
Usage: "Insurance to search",
Value: "premera",
Category: "Scraping",
},
),
Before: func(c *cli.Context) error {
if _, err := os.Stat(c.String("config")); err != nil {
Expand All @@ -150,10 +156,11 @@ func main() {
},
Action: func(c *cli.Context) error {

url, err := buildURL(c.String("state"), c.String("county"), c.String("city"), c.String("zip"))
if err != nil {
return err
}
// url, err := buildURL(c.String("state"), c.String("county"), c.String("city"), c.String("zip"))
// if err != nil {
// return err
// }
url := "https://www.psychologytoday.com/us/therapists/wa/king-county?category=trauma-and-ptsd&page=2&spec=6&spec=506"

config := scrape.Config{URL: url, CacheDir: filepath.Join(c.String("config"), "cache/")}

Expand Down
86 changes: 77 additions & 9 deletions graph/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions graph/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
type Therapist {
id: ID!
title: String!
accepting_appointments: String!
credentials: String!
verified: String!
statement: String!
Expand All @@ -15,6 +16,7 @@ type Therapist {

input TherapistFilters {
title: String
accepting_appointments: Boolean
credentials: String
verified: String
statement: String
Expand Down
19 changes: 10 additions & 9 deletions models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions scrape/scrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (s *scraper) Scrape(config Config) []api.Therapist {

c.OnHTML(".results-row", func(e *colly.HTMLElement) {
var therapist api.Therapist

e.ForEach(".results-row-info", func(i int, e *colly.HTMLElement) {
therapist.Title = e.ChildText(".profile-title")
therapist.Credentials = e.ChildText(".profile-subtitle-credentials")
Expand All @@ -60,6 +61,10 @@ func (s *scraper) Scrape(config Config) []api.Therapist {
therapist.Link = e.ChildAttr("a", "href")
})

e.ForEach(".profile-features", func(i int, e *colly.HTMLElement) {
therapist.AcceptingAppointments = e.ChildText(".accepting-appointments")
})

e.ForEach(".results-row-contact", func(i int, e *colly.HTMLElement) {
therapist.Phone = e.ChildText(".results-row-mob")
})
Expand Down
8 changes: 4 additions & 4 deletions sqlite/therapist.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ func (r *repository) therapistFilterQuery(query *bun.SelectQuery, params *api.Ge
}

if params.Verified != nil {
query.Where("? LIKE ?", bun.Ident("verified"), *params.Verified+"%")
query.Where("? LIKE ?", bun.Ident("verified"), "%"+*params.Verified+"%")
}

if params.Statement != nil {
query.Where("? LIKE ?", bun.Ident("statement"), *params.Statement+"%")
query.Where("? LIKE ?", bun.Ident("statement"), "%"+*params.Statement+"%")
}

if params.Phone != nil {
query.Where("? LIKE ?", bun.Ident("phone"), *params.Phone+"%")
query.Where("? LIKE ?", bun.Ident("phone"), "%"+*params.Phone+"%")
}

if params.Location != nil {
query.Where("? LIKE ?", bun.Ident("location"), *params.Location+"%")
query.Where("? LIKE ?", bun.Ident("location"), "%"+*params.Location+"%")
}

return query, nil
Expand Down

0 comments on commit e04220f

Please sign in to comment.