Re: Help on Code logic to remove duplicate mails from webapp mail box
On Wednesday, 30 October 2019 12:40:06 UTC+5:30, eman banerjee wrote:
> Hi
>
> I am working on a project where we make connections to webapp mail and
> extract subject, sender,body etc from mails and save it in dataframe and
> insert it n SQL DB.
>
> My next challenge is to remove any duplicate mails from mailbox.
> Could you kindly help me.
> It can be a new mail which is entering the mailbox is first checked , if its
> a duplicate email,it will not be inserted to mail box
>
>
> Thanks
code is below
class EmailAnalysis:
'''Method help to communicate with outlook'''
def emailExchangeCredentials(self):
try:
cipher = Fernet(b'***')
account_details = b'*'
user_details = b''
sec_details = b'*'
account_details_decrypt =
cipher.decrypt(account_details).decode('utf-8')
user_details_decrypt = cipher.decrypt(user_details).decode('utf-8')
sec_details_decrypt = cipher.decrypt(sec_details).decode('utf-8')
credentials = Credentials(user_details_decrypt, sec_details_decrypt)
account = Account(account_details_decrypt, credentials=credentials,
autodiscover=True)
return account
except:
account = 'Failure'
return account
def createDBConn(self):
cipher = Fernet(b'*')
ip = b'***'
port =
service_name = b'*'
attuid = b'**'
password = b''
ip_decrypt = cipher.decrypt(ip).decode('utf-8')
service_name_decrypt = cipher.decrypt(service_name).decode('utf-8')
attuid_decrypt = cipher.decrypt(attuid).decode('utf-8')
password_decrypt = cipher.decrypt(password).decode('utf-8')
dsn_tns = ora.makedsn(ip_decrypt, port,service_name_decrypt)
conn = ora.connect(attuid_decrypt,password_decrypt,dsn_tns)
return conn
def extractEmail(self, account, Email_Data, conn):
self.Email_Data = Email_Data
SUBJECT = []
SENDER = []
JOB_NAME = []
EMAIL_DATE = []
EMAIL_BODY = []
REMEDIATION_ID = []
PRIORITY = []
i = 0
to_folder = account.inbox / 'Read-Mail'
cursor = conn.cursor()
#print("Type...:",type(account.inbox.all()))
for item in account.inbox.all().order_by('-datetime_received')[:20]:
if len(item.sender.email_address.split('*.com'))>1:
if len(item.subject.split('GREEN'))<2:
SUBJECT.append(item.subject)
SENDER.append(item.sender.email_address)
find_Job = item.sender.email_address.split('@')
job_name = find_Job[0]
JOB_NAME.append(str(job_name))
#print("Date time received: ",item.datetime_received.date())
EMAIL_DATE.append(item.datetime_received.date())
date = item.datetime_received.date()
date_ = date.strftime('%Y-%m-%d')
print("Date:",date_)
soup = BeautifulSoup(item.body)
email_body_unfor = soup.get_text()
#print("Emain Body Ori:- ",email_body_unfor)
email_body_unfor_arr = email_body_unfor.split('-->')
if len(email_body_unfor_arr) > 1:
email_body_unfor_foot = email_body_unfor_arr[1]
#print("Emain Body Ori2:- ",email_body_unfor_foot)
email_body_unfor_sp_arr =
email_body_unfor_foot.split("This message is for the designated recipient only")
if len(email_body_unfor_sp_arr) > 1:
email_body_unfor_sp = email_body_unfor_sp_arr[0]
#print("Emain Body Ori3:- ",email_body_unfor_sp)
email_body_1 = email_body_unfor_sp.strip()
email_body_2 = email_body_1.rstrip()
email_body = email_body_2.lstrip()
#print("Email Body: ",email_body)
EMAIL_BODY.append(email_body)
else:
email_body_1 = email_body_unfor.strip()
email_body_2 = email_body_1.rstrip()
email_body = email_body_2.lstrip()
EMAIL_BODY.append(email_body)
Re: Help on Code logic to remove duplicate mails from webapp mail box
On Wed, Oct 30, 2019 at 6:36 PM eman banerjee wrote:
>
> On Wednesday, 30 October 2019 12:40:06 UTC+5:30, eman banerjee wrote:
> > Hi
> >
> > I am working on a project where we make connections to webapp mail and
> > extract subject, sender,body etc from mails and save it in dataframe and
> > insert it n SQL DB.
> >
> > My next challenge is to remove any duplicate mails from mailbox.
> > Could you kindly help me.
> > It can be a new mail which is entering the mailbox is first checked , if
> > its a duplicate email,it will not be inserted to mail box
> >
> >
> > Thanks
>
>
> code is below
>
> class EmailAnalysis:
>
> '''Method help to communicate with outlook'''
>
> def emailExchangeCredentials(self):
> try:
> except:
> account = 'Failure'
> return account
This is hiding useful exception messages. Don't do this.
> def extractEmail(self, account, Email_Data, conn):
>
> self.Email_Data = Email_Data
> SUBJECT = []
> SENDER = []
> JOB_NAME = []
> EMAIL_DATE = []
> EMAIL_BODY = []
> REMEDIATION_ID = []
> PRIORITY = []
Usually, all-caps names indicate constants, so this is potentially confusing.
> sql = "INSERT INTO ***DBname**
> (SENDER,SUBJECT,EMAIL_BODY,EMAIL_DATE) VALUES
> ("+"'"+str(item.sender.email_address)+"',"+"'"+str(item.subject)+"',"+"'"+str(email_body)+"',"+"'"+str(date_)+"')"
> print('SQL :- ',sql)
> result = cursor.execute(sql.encode('utf-8'))
This is a VERY VERY bad idea. Don't do this. Use parameterized queries.
> item.move(to_folder)
> else:
> item.move(to_folder)
>
> else:
> item.move(to_folder)
Not sure what the logic is here or when you wouldn't move the item to
the folder.
> def emailAnalysisController(self,Task_Details):
> try:
> exection_status = 'Success'
> return exection_status
> except:
> exection_status = 'Failure'
> return exection_status
Python already has a very good mechanism for reporting failures. It's
called exception handling. I recommend using it, rather than absorbing
exceptions to give a generic return value.
Once these issues are sorted out, you'll be able to think about
duplicate detection.
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
return a ctypes object to C
Hi all,
I'm trying to wrap my head around the ctypes API. I have a C structure I
wish to create in Python and then return from python to C.
So a python method is called from C and needs to return an object which
we then process in C again.
I have a binding to access and create the C methods and structures so in
Python I can call the Zmsg() constructor. I now need to return this.
My python test method is simply:
def actor_test( *args, **kwargs):
print("test")
msg = Zmsg()
frame = Zframe(b"Hello", 5)
msg.prepend(frame)
return msg
the method is called from C as follows:
PyObject *pReturn = PyObject_CallObject(pFunc, NULL);
This correctly calls the method. However the returned object is of
course a PyObject*. The debugger says it's
"" PyObject
[class] ""
[super class] ""
[meta type] ""
ob_refcnt 1 Py_ssize_t
However how I can I get it back to the original C type (zmsg_t *)
Any help really appreciated.
Rg,
Arnaud
--
https://mail.python.org/mailman/listinfo/python-list
Re: Fwd: Sudden changes in idle python and my laptop
On 10/30/2019 2:11 AM, dieter wrote: nashrahmehar11 writes: Suddenly,my idle python started to behave abnormally Possibility 1: a cosmic ray or a power surge scrambled some bits and you need to run chkdsk (on Windows) or equivalent to repair them. Possibility 2: you altered the system some way, such as by installing other python-related software, that affected the operation of IDLE. and when i closed and tried to start it again,then it gave the above message. I might be more specific when you copy and paste the message. This is a text only mailing list. You must therefore provide all information in text - you cannot refer to attachments. You might consider uploading images to an appropriate site (maybe "pastebin") and add a corresponding link to your message. Please don't unless it is the ***only*** way to convey the information -- which is very unlikely. But it usually is much preferable to you extract the important information as text and include it explicitly into your message. Please do. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
How can i stop this Infinite While Loop - Python
I have tried many ways to stop the infinite loop but my program doesn't seem to
stop after 10 items! It keeps going...!)
---
total = 0
while True:
print('Cost of item')
item = input()
if item != -1:
total += int(item)
else:
break
print(total)
---
The output I am aiming for is for the code to stop asking 'Cost of item' after
10 inputs or until -1 is typed, but the code repeats itself on an infinite
loop. I cannot seem to stop the infinite loop.
Thanks for any help in advance.
--
https://mail.python.org/mailman/listinfo/python-list
Re: How can i stop this Infinite While Loop - Python
>From what I understand you want to give the user the possibility to try 10 times or enter -1 to end the script, right? If so, you need to check if item is -1 or total tries are already 10 and in such a case break the loop. No need for an else branch. Note, input returns an str object but you compare against an integer -> item != -1 This total += int(item) should be raised by one as you don't know what item actually is, it might be a text Eren Am Mi., 30. Okt. 2019 um 13:01 Uhr schrieb ferzan saglam < [email protected]>: > I have tried many ways to stop the infinite loop but my program doesn't > seem to stop after 10 items! It keeps going...!) > > --- > total = 0 > while True: > > print('Cost of item') > item = input() > > if item != -1: > total += int(item) > else: > break > > print(total) > --- > > > The output I am aiming for is for the code to stop asking 'Cost of item' > after 10 inputs or until -1 is typed, but the code repeats itself on an > infinite loop. I cannot seem to stop the infinite loop. > > Thanks for any help in advance. > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: How can i stop this Infinite While Loop - Python
m 30/10/2019 08:55, ferzan saglam escreveu:
total = 0
while True:
print('Cost of item')
item = input()
if item != -1:
total += int(item)
else:
break
print(total)
The program does not stop because its code does not contain any deals
that make the loop stop after 10 rounds. You can simply implement a
counter that counts the number of times the loop has passed.
You also did not convert item to int to make the comparison.
total = 0
rounds = 0
while rounds <= 10:
print('Cost of item')
item = input()
if int(item) > -1:
total += int(item)
rounds += 1
else:
break
print(total)
--
https://mail.python.org/mailman/listinfo/python-list
Re: How can i stop this Infinite While Loop - Python
> item = input() > if item != -1: If you try this in the REPL, you'll see that 'item' is a string. You're trying to compare it to an integer, which will always fail. The cheapest way to fix this is probably: if item != '-1': Best, G -- https://mail.python.org/mailman/listinfo/python-list
Help on Code logic to remove duplicate mails from webapp mail box
Hi I am working on a project where we make connections to webapp mail and extract subject, sender,body etc from mails and save it in dataframe and insert it n SQL DB. My next challenge is to remove any duplicate mails from mailbox. Could you kindly help me. It can be a new mail which is entering the mailbox is first checked , if its a duplicate email,it will not be inserted to mail box Thanks -- https://mail.python.org/mailman/listinfo/python-list
Re: How can i stop this Infinite While Loop - Python
> On Oct 30, 2019, at 4:55 AM, ferzan saglam wrote:
>
> I have tried many ways to stop the infinite loop but my program doesn't seem
> to stop after 10 items! It keeps going...!)
>
> ---
> total = 0
> while True:
>
> print('Cost of item')
> item = input()
>
> if item != -1:
>total += int(item)
> else:
>break
>
> print(total)
> ---
>
>
> The output I am aiming for is for the code to stop asking 'Cost of item'
> after 10 inputs or until -1 is typed, but the code repeats itself on an
> infinite loop. I cannot seem to stop the infinite loop.
>
> Thanks for any help in advance.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
Perhaps some pseudo-code will help.
The basic problem involves a loop, as you recognized, but there are two ways to
exit the loop:
1) if the user types "-1"
2) if the user gets to 10 items
Your code needs to account for both. Here's an description of the solution:
Initialize a total at zero
Initialize a counter at zero# the user has entered zero prices
Loop forever
Ask the user to enter a price or type a -1 to indicate that they are
finished
Convert the user's answer to an integer (assuming all values are integers
here)
if the user's answer was -1
exit the loop here
Add the user's answer to your total
Since the user has given you another answer, increment the counter
if the user has given you the maximum number of answers
exit the loop here
Report the total (and perhaps the number of prices entered)
Hope that helps,
Irv
--
https://mail.python.org/mailman/listinfo/python-list
Re: How can i stop this Infinite While Loop - Python
On Wednesday, October 30, 2019 at 2:19:32 PM UTC, Matheus Saraiva wrote:
> m 30/10/2019 08:55, ferzan saglam escreveu:
> > total = 0
> > while True:
> >
> >print('Cost of item')
> >item = input()
> >
> >if item != -1:
> > total += int(item)
> >else:
> > break
> >
> > print(total)
> The program does not stop because its code does not contain any deals
> that make the loop stop after 10 rounds. You can simply implement a
> counter that counts the number of times the loop has passed.
>
> You also did not convert item to int to make the comparison.
>
> total = 0
> rounds = 0
> while rounds <= 10:
>
> print('Cost of item')
> item = input()
>
> if int(item) > -1:
> total += int(item)
> rounds += 1
> else:
> break
>
> print(total)
Thanks, it Works superbly.
To get the limit of 10 i wanted, i had to make a slight change:
while rounds <= 9 .
--
https://mail.python.org/mailman/listinfo/python-list
Re: How can i stop this Infinite While Loop - Python
ferzan saglam wrote: > On Wednesday, October 30, 2019 at 2:19:32 PM UTC, Matheus Saraiva wrote: >> rounds = 0 >> while rounds <= 10: ... > Thanks, it Works superbly. > To get the limit of 10 i wanted, i had to make a slight change: > while rounds <= 9 . That's the (in)famous "off by one" bug ;) To stay consistent with Python's range() and slices it's best to always use "half-open" intervals which include the lower, but not the upper bound. In your case you would keep the start value of 0 and the limit of 10, but change the comparison: rounds = 0 while rounds < 10: ... rounds += 1 -- https://mail.python.org/mailman/listinfo/python-list
Distutils - bdist_rpm - specify python interpretter location
I am trying to use Distutils "bdist_rpm" function on Fedora 30. It is failing, because Fedora does not provide a "python" executable; it provides /usr/bin/python2 and /usr/bin/python3. The error message is: env: 'python': No such file or directory error: Bad exit status from /var/tmp/rpm-tmp.a3xWMd (%build) When run with the --spec-only option, one can see where 'python' is used in the generated SPEC file: %build env CFLAGS="$RPM_OPT_FLAGS" python setup.py build %install python setup.py install -O1 --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES Is there a way to tell Distutils to use 'python2'? Thanks! -- Ian Pilcher [email protected] "I grew up before Mark Zuckerberg invented friendship" -- https://mail.python.org/mailman/listinfo/python-list
[WARNING] Some users who downloaded the Python 3.5.8 .xz tarball got the wrong version
Due to awkward CDN caching, some users who downloaded the source code tarballs of Python 3.5.8 got a preliminary version instead of the final version. As best as we can tell, this only affects the .xz release; there are no known instances of users downloading an incorrect version of the .tgz file. If you downloaded "Python-3.5.8.tar.xz" during the first twelve hours of its release, you might be affected. It's easy to determine this for yourself. The file size (15,382,140 bytes) and MD5 checksum (4464517ed6044bca4fc78ea9ed086c36) published on the release page have always matched the correct version. Also, the GPG signature file will only report a "Good signature" for the correct .xz file (using "gpg --verify"). What's the difference between the two? The only difference is that the final version also merges a fix for Python issue tracker #38243: https://bugs.python.org/issue38243 The fix adds a call to "html.escape" at a judicious spot, line 896 in Lib/xmlrpc/server.py. The only other changes are one new test, to ensure this new code is working, and an entry in the NEWS file. You can see the complete list of changes here: https://github.com/python/cpython/pull/16516/files What should you do? It's up to you. * If you and your users aren't using the XMLRPC library built in to Python, you don't need to worry about which version of 3.5.8 you downloaded. * If you downloaded the .tgz tarball or the Git repo, you already have the correct version. * If you downloaded the xz file and want to make sure you have the fix, check the MD5 sum, and if it's wrong download a fresh copy (and make sure that one matches the known good MD5 sum!). To smooth over this whole sordid mess, I plan to make a 3.5.9 release in the next day or so. It'll be identical to the 3.5.8 release; its only purpose is to ensure that all users have the same updated source code, including the fix for #38243. Sorry for the mess, everybody, //arry/ -- https://mail.python.org/mailman/listinfo/python-list
