Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Dependencies and Comments #303

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.work.sum
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will need to check the comparability of the existing dependencies first as I still have some open PRs from dependabot to review.

Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpE
github.com/tinylib/msgp v1.1.8/go.mod h1:qkpG+2ldGg4xRFmx+jfTvZPxfGFhi64BcnL9vkCm/Tw=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
17 changes: 9 additions & 8 deletions scraper/pkg/tripadvisor/tripadvisor.go
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the newline as it's not necessary. Function comments should with start with the function name.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"time"
)

// MakeRequest is a function that sends a POST request to the TripAdvisor GraphQL endpoint
// MakeRequest sends a POST request to the TripAdvisor GraphQL endpoint
func MakeRequest(client *http.Client, queryID string, language []string, locationID uint32, offset uint32, limit uint32) (responses *Responses, err error) {

/*
Expand Down Expand Up @@ -107,7 +107,7 @@ func MakeRequest(client *http.Client, queryID string, language []string, locatio
return &responseData, err
}

// GetQueryID is a function that returns the query ID for the given query type
// GetQueryID returns the query ID for the given query type
func GetQueryID(queryType string) (queryID string) {

switch queryType {
Expand All @@ -122,7 +122,7 @@ func GetQueryID(queryType string) (queryID string) {
}
}

// FetchReviewCount is a function that fetches the review count for the given location ID and query type
// FetchReviewCount fetches the review count for the given location ID and query type
func FetchReviewCount(client *http.Client, locationID uint32, queryType string, languages []string) (reviewCount int, err error) {

// Get the query ID for the given query type.
Expand Down Expand Up @@ -150,7 +150,7 @@ func FetchReviewCount(client *http.Client, locationID uint32, queryType string,
return 0, fmt.Errorf("no reviews found for location ID %d", locationID)
}

// CalculateIterations is a function that calculates the number of iterations required to fetch all reviews
// CalculateIterations calculates the number of iterations required to fetch all reviews
func CalculateIterations(reviewCount uint32) (iterations uint32) {

// Calculate the number of iterations required to fetch all reviews
Expand All @@ -164,14 +164,14 @@ func CalculateIterations(reviewCount uint32) (iterations uint32) {
return iterations
}

// CalculateOffset is a function that calculates the offset for the given iteration
// CalculateOffset calculates the offset for the given iteration
func CalculateOffset(iteration uint32) (offset uint32) {
// Calculate the offset for the given iteration
offset = iteration * ReviewLimit
return offset
}

// GetURLType is a function that validates the URL and returns the type of URL
// GetURLType validates the URL and returns the type of URL
func GetURLType(url string) string {
if tripAdvisorHotelURLRegexp.MatchString(url) {
return "HOTEL"
Expand All @@ -192,7 +192,7 @@ func GetURLType(url string) string {
return ""
}

// ParseURL is a function that parses the URL and returns the location ID and the location name
// ParseURL parses the URL and returns the location ID and the location name
func ParseURL(url string, locationType string) (locationID uint32, locationName string, error error) {
// Sample hotel url: https://www.tripadvisor.com/Hotel_Review-g188107-d231860-Reviews-Beau_Rivage_Palace-Lausanne_Canton_of_Vaud.html
// Sample restaurant url: https://www.tripadvisor.com/Restaurant_Review-g187265-d11827759-Reviews-La_Terrasse-Lyon_Rhone_Auvergne_Rhone_Alpes.html
Expand Down Expand Up @@ -233,6 +233,7 @@ func ParseURL(url string, locationType string) (locationID uint32, locationName
}
}

// WriteReviewsToJSONFile writes the reviews to a JSON file
func WriteReviewsToJSONFile(reviews []Review, location Location, fileHandle *os.File) error {
feedback := Feedback{
Location: location,
Expand All @@ -248,7 +249,7 @@ func WriteReviewsToJSONFile(reviews []Review, location Location, fileHandle *os.
return nil
}

// SortReviewsByDate is a function that sorts the reviews by date
// SortReviewsByDate sorts the reviews by date
// This function modifies the original slice
func SortReviewsByDate(reviews []Review) {
const layout = "2006-01-02" // Move the layout constant here to keep it scoped to the sorting logic
Expand Down