Skip to content

Commit

Permalink
Merge pull request #49 from muly/urlParsing
Browse files Browse the repository at this point in the history
issues
  • Loading branch information
muly authored Dec 9, 2023
2 parents ee10cbd + 7ded2d2 commit fb7b0e6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
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
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 @@ -23,10 +23,11 @@ const (
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 sendTrackNotificationEmail(t trackInput, p scrape.Product) error {

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 @@ func prepareTrackNotificationEmail(t trackInput, p scrape.Product) (*mail.Messag
} 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
}

0 comments on commit fb7b0e6

Please sign in to comment.