Skip to content

Instantly share code, notes, and snippets.

@exemplum100
Created September 5, 2023 14:36
Show Gist options
  • Save exemplum100/35037b06c44c9af8b4fe307f69ee8d9c to your computer and use it in GitHub Desktop.
Save exemplum100/35037b06c44c9af8b4fe307f69ee8d9c to your computer and use it in GitHub Desktop.
pyOutlookRemind
#How it work
#:Search info in incoming messages and remind about new value, into Outlook from third-system, without last(closed) selfstatus
#:Last selfstatus substitution in closed_list.txt manualy
#:Make txt file with some info, for reminder button
#:After, remind about new messages
#(foxes in comment just for ex)
import os
import time
from datetime import datetime
import win32com.client as win32
import re as re
from winotify import Notification # best notify app for this
cnt=0 #value for check exists
shdb=[] #list for notrify print
#add to list from txt with 3 status, need to compare selfstatus
closed=[]
with open('closed_list.txt','r',encoding='utf-8') as closed_list:
for i in closed_list.readlines():
i2=i.strip('\n')
closed.append(i2)
#load mail app and forming .txt to clear (forming txt always new)
olApp = win32.Dispatch('Outlook.Application')
olNS = olApp.GetNameSpace('MAPI') # NameSpaces need for attchm or folders search
inbox = olNS.GetDefaultFolder(6).folders['SPEC_FOLDER'] #spec folder, 6- incoming
messages = inbox.Items #sly type list
with open('foxes_list.txt', 'w') as xfile: #reload TXT
xfile.close()
#------------------------------------------------------------------------
#-------------------------------=:^.^:=----------------------------------
#------------------------------------------------------------------------
for i in range(len(messages)-15,len(messages)): #choose 15 last messages
if cnt>100: #FYA, just
break
else:
sjstr=messages[i].subject #take mess subj (for each i)
bodystr=messages[i].body #take mess body (for each i)
x=re.search(r'(ID\d+)',bodystr) # search in BODY
if x:
shdbk= str(x.group(0)) #ready-str from BODY, first match
xx= re.findall(r'DATETIME:\s+\d+/\d+/\d+ \d+:\d+:\d+', bodystr) # find needed list in BODY
xxx= re.findall(r'DATETIME2:\s+\d+/\d+/\d+ \d+:\d+:\d+', bodystr) # find needed list in BODY (2)
sj=re.search(r'FOXES BACKYARD ALARM',sjstr) #search needed in SUBJ
if sj and shdbk not in closed: #if foxes real (subj search) and not closed in jail list (and not in closed_list)
try:
with open('foxes_list.txt', 'a') as xfile: #create info file about non-closed foxex
xfile.write(str(shdbk)+'\n')
xfile.write(str(xxx[0])+'\n')
xfile.write(str(xx[0])+'\n\n')
xfile.close()
print(x.group(0))
print(xx[0])
shdb.append(shdbk) #add foxes to list for notify
except:
pass
cnt+=1 #add cnt for exist fox check
toast = Notification(app_id="CATCHFOXES!", #title1
title="NEW FOXES", #title2
msg='File ready for foxes: '+ str(shdb), #msg with list of foxes
duration= "long", #duration
icon=r"C:\fox\foxjail\tail.png") #ico
toast.add_actions(label="Open file", #make button, label
launch=r'C:\Users\fox\notes\foxdiscr.txt') #launch path, (can be url for ex.)
if cnt>0 and len(str(shdb))<240: #we add cnt after try\except fro check, and len here for except errors
toast.show() #show func on desktop
elif cnt==0: #same, but for null value
toast = Notification(app_id="CATCHFOXES!",
title="NEW FOXES",
msg='No foxes',
duration= "long",
icon=r"C:\fox\foxjail\tail.png")
toast.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment