Skip to content
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
10 changes: 5 additions & 5 deletions main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,31 @@
if prev_status.read_tkt_status()!=cur_stat:
thd_id,msg_id,first,line_no=prev_status.read_msg_status()

if Decimal(sub(r'[^\d.]', '',cur_stat)) <= 10500.00:
msg_id=send_mail.send_thread('The price is '+cur_stat+' at '+str(now),thd_id,msg_id,first) #sending the mail with updated price if price above threshold
if Decimal(sub(r'[^\d.]', '',cur_stat)) <=xxxxxxxx:
msg_id=send_mail.send_thread('xxxxxxxxxxxxxx'+cur_stat+' xxxxxxxxxxxxxxxx '+str(now),thd_id,msg_id,first) #sending the mail with updated price if price above threshold

update_price_history.update_price(cur_stat,line_no,now) #updating the excel sheet with the price to maintain price history line_no=str(int(line_no)+1)
line_no=str(int(line_no)+1)
update_status.update_info_status(cur_stat,msg_id,msg_id,first,line_no)


print("Tracked Fitbit charge 4 price: ",now)
print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ",now)
fails=0 #after a success the fails counter is brought back to zero
err_msg=0
time.sleep(3600)
except Exception as e:
fails=fails+1
if fails>=3 and err_msg==0:
try: #this part will send email message in case of there is any failure in tracking
error_msg="Failed to track the product for 3 consecutive times, latest at: "+str(now)+" Please see the server logs, ASAP!!!"
error_msg="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"+str(now)+" xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
thd_id,msg_id,first,line_no=prev_status.read_msg_status()
msg_id=send_mail.send_thread(error_msg,thd_id,msg_id,first)
update_status.update_error_status(msg_id,msg_id,first)
err_msg=1
except Exception as err:
pass

print("Failed to track the product at: "+str(now)+" Error: "+str(e)+". Trying again...")
print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"+str(now)+" xxxxxxxxxxxxxxxxxxxxxxxxx "+str(e)+".xxxxxxxxxxxxxxxxxxxxxxxx")
time.sleep(900)


Expand Down
4 changes: 2 additions & 2 deletions prev_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def read_tkt_status():
credentials= ServiceAccountCredentials.from_json_keyfile_name('credentials_sheets.json', scope)

gc= gspread.authorize(credentials)
wks= gc.open('FitBit Tracker').sheet1 #change the google sheets database name
wks= gc.open('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx').sheet1 #change the google sheets database name

return wks.acell('B1').value

Expand All @@ -15,6 +15,6 @@ def read_msg_status():
credentials= ServiceAccountCredentials.from_json_keyfile_name('credentials_sheets.json', scope)

gc= gspread.authorize(credentials)
wks= gc.open('FitBit Tracker').sheet1 #change the google sheets database name
wks= gc.open('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx').sheet1 #change the google sheets database name

return wks.acell('B2').value,wks.acell('B3').value,wks.acell('B4').value,wks.acell('B5').value
15 changes: 7 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
secure-smtplib==0.1.1
python-time==0.1.2
google-auth-oauthlib==0.4.1
google-api-python-client==1.12.2
gspread==3.6.0
oauth2client==4.1.3
requests==2.25.1
beautifulsoup4==4.9.3
python-time
google-auth-oauthlib
google-api-python-client
gspread
oauth2client
requests
beautifulsoup4
28 changes: 15 additions & 13 deletions send_mail.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import smtplib
from Google import Create_Service
import base64
from email.mime.multipart import MIMEMultipart
Expand All @@ -15,30 +14,33 @@ def send_thread(current_status,thd_id,msid,first): #sending email repl
service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES)

if first==str(1):
emailMsg='Welcome to email thread for FitBit Charge 4 Amazon Price Tracker. Current price is:'+current_status+'\n'+'Visit https://www.amazon.in/Fitbit-Charge-Fitness-Tracker-Non-NFC/dp/B084CQ41M2/ref=sr_1_8?dchild=1&keywords=fitbit%2Bcharge%2B3&qid=1608032936&sr=8-8&th=1 for more details.' #change the body here for first mail
emailMsg='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxx'+current_status+'\n'+'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.' #change the body here for first mail
mimeMessage = MIMEMultipart()
mimeMessage['to'] = 'sudb97@outlook.com' #change the recipient of the mail
mimeMessage['subject'] = 'FitBit Charge 4 Amazon Price Tracker' #Change the subject for the 1st mail
mimeMessage['to'] = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' #change the recipient of the mail
mimeMessage['subject'] = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' #Change the subject for the 1st mail
mimeMessage.attach(MIMEText(emailMsg, 'plain'))
raw_string = base64.urlsafe_b64encode(mimeMessage.as_bytes()).decode()

message = service.users().messages().send(userId='me', body={'raw': raw_string}).execute()

return message["id"]

else:
msg_id,ref_id=retrive_ids.get_mime_ids(msid)
message = MIMEText('There is an update: '+current_status+'\n'+'Please visit https://www.amazon.in/Fitbit-Charge-Fitness-Tracker-Non-NFC/dp/B084CQ41M2/ref=sr_1_8?dchild=1&keywords=fitbit%2Bcharge%2B3&qid=1608032936&sr=8-8&th=1 for more details.') #change the body of the threaded mail
message['to'] = 'sudb97@outlook.com' #change the recipient of the thread mail
message['from'] = 'iem2015f@gmail.com'
message['subject'] = 'FitBit Charge 4 Amazon Price Tracker' #Change the subject of the threaded mail
message['In-Reply-To'] = msg_id
message['References'] = ref_id
message = MIMEText('xxxxxxxxxxxxxxxxxxxxxxxx'+current_status+'\n'+'Please visit https://www.amazon.in/Fitbit-Charge-Fitness-Tracker-Non-NFC/dp/B084CQ41M2/ref=sr_1_8?dchild=1&keywords=fitbit%2Bcharge%2B3&qid=1608032936&sr=8-8&th=1 for more details.') #change the body of the threaded mail
message['to'] = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' #change the recipient of the thread mail
message['subject'] = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' #Change the subject of the threaded mail
message['In-Reply-To'] = msg_id
message['References'] = ref_id
sz_message = message.as_string()
raw_msg_byte =base64.urlsafe_b64encode(six.ensure_binary(sz_message))
raw_msg = six.ensure_str(raw_msg_byte)
new_email = {'raw': raw_msg}
new_email['threadId'] = thd_id
new_email['threadId'] = thd_id

sent=service.users().messages().send(userId='me', body=new_email).execute()
return sent["id"]
return sent["id"]



#Note : In place of XXXXXXXXXXXXXXXXXXXXXX please writ according to your requirement
2 changes: 1 addition & 1 deletion update_price_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def update_price(current_status,line_no,date):
credentials= ServiceAccountCredentials.from_json_keyfile_name('credentials_sheets.json', scope)

gc= gspread.authorize(credentials)
wks= gc.open('FitBit Tracker').get_worksheet(1) #change the google sheets database name
wks= gc.open('xxxxxxxxxxxxxxxxxxxxxx').get_worksheet(1) #change the google sheets database name


wks.update_acell('A'+line_no,str(date))
Expand Down
4 changes: 2 additions & 2 deletions update_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def update_info_status(current_status,thd_id,msg_id,first,line_no): #upd
credentials= ServiceAccountCredentials.from_json_keyfile_name('credentials_sheets.json', scope)

gc= gspread.authorize(credentials)
wks= gc.open('FitBit Tracker').sheet1 #change the google sheets database name
wks= gc.open('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx').sheet1 #change the google sheets database name

if first==str(1):
wks.update_acell('B1',current_status)
Expand All @@ -27,7 +27,7 @@ def update_error_status(thd_id,msg_id,first): #updates the status when e
credentials= ServiceAccountCredentials.from_json_keyfile_name('credentials_sheets.json', scope)

gc= gspread.authorize(credentials)
wks= gc.open('FitBit Tracker').sheet1 #change the google sheets database name
wks= gc.open('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx').sheet1 #change the google sheets database name

if first==str(1):
#wks.update_acell('B1',current_status)
Expand Down