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

issues #49

Merged
merged 5 commits into from
Dec 9, 2023
Merged
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: 1 addition & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func availabilityHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Pa
w.WriteHeader(http.StatusBadRequest)
return
}

t.TypeOfRequest=requestTypeAvailability
muly marked this conversation as resolved.
Show resolved Hide resolved
if err := validateAndCleanup(&t); err != nil {
if errors.Is(err, websiteNotSupported) {
w.WriteHeader(http.StatusNotAcceptable)
Expand Down
4 changes: 2 additions & 2 deletions chrome-exten/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ <h3>SELECT AN OPTION</h3>
<label><input type="radio" name="option" value="price">Track Price</label>
<div id="priceThreshold" style="display: none;">
<label for="minPrice">Min Price Threshold</label>
<input type="number" id="minPrice" min="0" step="0.01" />
<input type="number" id="minPrice" min="0" step="0.01" required/>
</div>
<div id="zipcode" style="display: none;">
<label for="zipcodeValue">Zip Code</label>
<input type="number" id="zipcodeValue" min="0" step="0.01" />
<input type="number" id="zipcodeValue" min="0" step="0.01" required/>
</div>
<button id="submitBtn" type="submit">TRACK</button>
<script src="./popup.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions chrome-exten/popup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//var apiurl=`https://smuly-test-ground.ue.r.appspot.com`
var apiurl=`http:localhost:8006`
var apiurl=`https://smuly-test-ground.ue.r.appspot.com`
//var apiurl=`http:localhost:8006`
var activeUrl
let emailid
chrome.identity.getAuthToken({ interactive: true, scopes: ['email'] }, function(token) {
Expand Down
18 changes: 12 additions & 6 deletions email.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

secretmanager "cloud.google.com/go/secretmanager/apiv1"
"cloud.google.com/go/secretmanager/apiv1/secretmanagerpb"
scrape "github.com/muly/product-scrape"

Check failure on line 13 in email.go

View workflow job for this annotation

GitHub Actions / build

reading github.com/muly/product-scrape/go.mod at revision v1.0.5: git ls-remote -q origin in /home/runner/go/pkg/mod/cache/vcs/d043bf9c73c3bb2318b19657b8787a2b627b6ad39a1400ffc49be744b99779db: exit status 128:
"gopkg.in/mail.v2"
)

Expand All @@ -23,10 +23,11 @@
const notificationEmailBody = `<html>
<body style="font-family: Arial, Helvetica, sans-serif; text-align: center;">
<div style="background-color: #ffffff; padding: 10px 20px; border-radius: 10px; max-width: 400px; margin: 0 auto;">
<p style="font-weight: bolder; color: #2d71ac; font-size: 20px;">Product is available</p>
<img style="max-width: 100%; margin: 3px 0 0; border-radius: 8px; width: 85px; height: 85px;" src="cid:logo.png" alt="Logo">
<h2 style="font-weight: bolder; color: #2d71ac; font-size: 20px;">Product is available</h2>
<img style="max-width: 100%; margin: 3px 0; border-radius: 8px;" src="product-image" alt="Product Image">
<p class="product-name">Product Name</p>
<p style="color: #292627; font-weight: bolder ; font-size:15px"> HURRAY! The product you are looking for is available at price(₹value)</p>
<p style="color: #292627; font-weight: bolder ; font-size:15px"> HURRAY! The product you are looking for is PRICE
<a style="background-color: #000; color: #fff; padding: 10px 20px; text-decoration: none; font-weight: bold; display: inline-block; margin-top: 10px; border-radius: 4px;" href="PRODUCT_URL">Place Order</a>
</div>
</body>
Expand Down Expand Up @@ -87,8 +88,7 @@

func prepareTrackNotificationEmail(t trackInput, p scrape.Product) (*mail.Message, error) {
var emailBody string
priceString := strconv.FormatFloat(p.Price, 'f', -1, 64)
log.Println(p.Name)
var priceString string
log.Println("creating mail")
m := mail.NewMessage()
m.SetHeader("From", systemEmailID)
Expand All @@ -100,11 +100,17 @@
} else {
return nil, fmt.Errorf("invalid request type %s", t.TypeOfRequest)
}
m.Embed("./chrome-exten/logo.png") //previously i got this error because of wrong path gomail: could not send email 1: open /chrome-exten/logo.png: no such file or directory
emailBody = strings.Replace(notificationEmailBody, "PRODUCT_URL", t.URL, -1)
emailBody = strings.Replace(emailBody, "Product Name", p.Name, -1)
emailBody = strings.Replace(emailBody, "product-image", p.Image, -1)
emailBody = strings.Replace(emailBody, "value", priceString, -1)

if p.Price != 0 {
priceString = strconv.FormatFloat(p.Price, 'f', -1, 64)
emailBody = strings.Replace(emailBody, "PRICE", "available at ₹"+priceString+"</p>", -1)
} else {
emailBody = strings.Replace(emailBody, "PRICE", "available now</p>", -1)
}

m.SetBody("text/html", emailBody)
return m, nil
}
Loading