diff --git a/main_test.py b/main_test.py index e861cdf..9229196 100644 --- a/main_test.py +++ b/main_test.py @@ -22,15 +22,15 @@ 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) @@ -38,7 +38,7 @@ 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) @@ -46,7 +46,7 @@ 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) diff --git a/prev_status.py b/prev_status.py index 346292a..fb9a6b2 100644 --- a/prev_status.py +++ b/prev_status.py @@ -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 @@ -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 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index cd069b5..184d842 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/send_mail.py b/send_mail.py index d47ecc3..eb9ef1c 100644 --- a/send_mail.py +++ b/send_mail.py @@ -1,4 +1,3 @@ -import smtplib from Google import Create_Service import base64 from email.mime.multipart import MIMEMultipart @@ -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"] \ No newline at end of file + return sent["id"] + + + + #Note : In place of XXXXXXXXXXXXXXXXXXXXXX please writ according to your requirement diff --git a/update_price_history.py b/update_price_history.py index 8e4b284..32d2297 100644 --- a/update_price_history.py +++ b/update_price_history.py @@ -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)) diff --git a/update_status.py b/update_status.py index 44d960d..528c5be 100644 --- a/update_status.py +++ b/update_status.py @@ -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) @@ -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)