Re: How to compare timestamps in python

2018-10-23 Thread MRAB

On 2018-10-23 16:18, Asad wrote:

Hi All ,

   I have just playing with python , I am stuck for the following
problem :

file1 :
Patching tool version 12.1.0.2.0 Production on Fri Feb 23 01:10:28 2018

Bootstrapping registry and package to current versions...done
statement ERR-2001: table is corrupt check for cause

could not determine the current status.

Patching tool version 12.1.0.2.0 Production on Fri Feb 23 01:10:58 2018

file2 :

  LOG file opened at 02/03/18 01:11:05

DUP-05004:   statement1
DUP-05007:   statement2


  LOG file opened at 02/03/18 01:11:14

DUP-05004:   statement1

DUP-05007:   statement2


  LOG file opened at 02/23/18 01:10:33

DUP-05004:   statement1

DUP-05007:   statement2

I need to look for the ERR-2001 in file1 if it matches then go to file2 and
print the message nearest to the timestamp found in file1 within two
minutes of range .


1) What regex I use get the timestamp from file 1 and then file 2  ?

2) How to I acheive
  so in this case file1 Start:  Fri Feb 23 01:10:28 2018
End time :  Fri Feb 23 01:10:58 2018
check in file 2 nearest to file1 end time : 02/23/18 01:10:33

Thanks in advance,


The datetime in file1 matches this regex:

\b\w{3} \w{3} \d+ \d{2}:\d{2}:\d{2} \d{4}\b

When you have the datetime string, you need to parse it with 
datetime.datetime.strptime; that needs to be given the format that 
describes the datetime:


%a %b %d %H:%M:%S %Y

The datetime in file2 matches this regex:

\b\d{2}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}\b

and the format for datetime.datetime.strptime is:

%m/%d/%y %H:%M:%S

Finding the nearest date/time is simple: calculate the difference 
between the 2 datetimes (which will return a datetime.timedelta) and 
pick the one with the smallest absolute (abs(...)) value of its 
.total_seconds() method.


--
https://mail.python.org/mailman/listinfo/python-list


How to compare timestamps in python

2018-10-23 Thread Asad
Hi All ,

  I have just playing with python , I am stuck for the following
problem :

file1 :
Patching tool version 12.1.0.2.0 Production on Fri Feb 23 01:10:28 2018

Bootstrapping registry and package to current versions...done
statement ERR-2001: table is corrupt check for cause

could not determine the current status.

Patching tool version 12.1.0.2.0 Production on Fri Feb 23 01:10:58 2018

file2 :

 LOG file opened at 02/03/18 01:11:05

DUP-05004:   statement1
DUP-05007:   statement2


 LOG file opened at 02/03/18 01:11:14

DUP-05004:   statement1

DUP-05007:   statement2


 LOG file opened at 02/23/18 01:10:33

DUP-05004:   statement1

DUP-05007:   statement2

I need to look for the ERR-2001 in file1 if it matches then go to file2 and
print the message nearest to the timestamp found in file1 within two
minutes of range .


1) What regex I use get the timestamp from file 1 and then file 2  ?

2) How to I acheive
 so in this case file1 Start:  Fri Feb 23 01:10:28 2018
   End time :  Fri Feb 23 01:10:58 2018
check in file 2 nearest to file1 end time : 02/23/18 01:10:33

Thanks in advance,
-- 
Asad Hasan
+91 9582111698


-- 
Asad Hasan
+91 9582111698
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: email automation

2018-10-23 Thread Thomas Jollans
On 2018-10-23 13:58, Brian J. Oney via Python-list wrote:
> Now that it seems that I will be writing this. What is the recommended way to
> set up a timer. I know 2 system options, systemd timers and cron jobs. I
> prefer the former for the handy logging options. What about a python solution?

celery?

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: email automation

2018-10-23 Thread Brian J. Oney via Python-list
On Tue, 2018-10-23 at 10:31 +0100, Ali Rıza KELEŞ wrote:
> On Tue, 23 Oct 2018 at 09:07, Thomas Jollans  wrote:
> > > After some basic research I have a few options:
> > > 
> > >  1. Grapple with OpenEMM (interesting software, has python library, 
> > > still alive and kicking, a bit overkill for my use-case);
> > >  2. build on the examples in 'Automate the boring stuff';
> > 
> > From briefly skimming the relevant section, it looks like this gives
> > some examples with smtplib and imaplib. That sounds like a good place to
> > start!
> > 
> > If you happen to have a server (VPS, Raspberry Pi, PC, whatever) running
> > a full MTA that you can forward your emails to, you could feed the
> > relevant messages to your script directly with the help of procmail,
> > rather than polling an IMAP server.
> 
> +1
> 
> I experienced procmail and worked like a charm for me, in a case like
> yours. My script was parsing emails to grab some URIs of binary
> objects and queue them to be processed later.
> 
> You can easily trigger a python script and do whatever you need in
> that script. If it is a long term process, you should just parse email
> and use queues for the rest.
> 

Thank you for the insights. The developer of procmail says to avoid it, as the
last update was in 2001. Supposedly there are also some security concerns.
The mail server does some pretty good filtering already.

I made the mistake of being vague about the problem. Let me specify.

  - General Problem: too many emails to answer with due care
- Technical Problem 1: can't be run on mail server.
- Technical Problem 2: answers needed in 2 and possibly 4 languages.
- Future Problem 3: don't have resources to maintain the solution forever
- Future Problem 4: software may be running in many different countries
  with different languages and legal frameworks.
  - Goal: lighten the load 
- Potential: many emails pose questions to information already on the
  website.
  - Potential solution: automate personalized replies with relevant
information.

Nonetheless, barring a tip to an existing solution, I will be rolling my own.

Off the top of my head, I image the setup being eerily similar to a flask
website. I would rely on smtplib, imaplib, nltk, pyzmail, and jinja2.

Draft Algorithm:
  1. read mail
  2. tokenize body's contents
  3. apply logic to determine answer
  4. render appropriate answer template
  5. send email
  6. refile email

maildog/
  app.py
  answer_logic/
english.csv
german.csv
french.csv
  maildog/
__init__.py
send_mail.py
read_mail.py
refile_mail.py
decide_answer.py
  templates/
base.html
base.txt
info.html
info.txt
schedule.html
schedule.txt
  tests/
test_answer_common_email.py
test_explain_upcoming_schedule.py
test_read_email.py


Somehow I think someone smarter already solved this niche case. A part of me
wants to delve into OpenEMM. The rest wants to write code.

Now that it seems that I will be writing this. What is the recommended way to
set up a timer. I know 2 system options, systemd timers and cron jobs. I
prefer the former for the handy logging options. What about a python solution?
What would the advantage of a python queue be over a systemd timer? I guess
that's an apples an oranges comparison. In my case I most likely would have a
raspberry pi running a python script to read and possibly answer any emails.

Thanks again for the tips.

Regards,
Brian

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: email automation

2018-10-23 Thread Ali Rıza KELEŞ
On Tue, 23 Oct 2018 at 09:07, Thomas Jollans  wrote:
> > After some basic research I have a few options:
> >
> >  1. Grapple with OpenEMM (interesting software, has python library, 
> > still alive and kicking, a bit overkill for my use-case);
> >  2. build on the examples in 'Automate the boring stuff';
>
> From briefly skimming the relevant section, it looks like this gives
> some examples with smtplib and imaplib. That sounds like a good place to
> start!
>
> If you happen to have a server (VPS, Raspberry Pi, PC, whatever) running
> a full MTA that you can forward your emails to, you could feed the
> relevant messages to your script directly with the help of procmail,
> rather than polling an IMAP server.

+1

I experienced procmail and worked like a charm for me, in a case like
yours. My script was parsing emails to grab some URIs of binary
objects and queue them to be processed later.

You can easily trigger a python script and do whatever you need in
that script. If it is a long term process, you should just parse email
and use queues for the rest.

-- 
--
Ali Rıza Keleş
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: email automation

2018-10-23 Thread Thomas Jollans
On 22/10/2018 18:35, Brian Oney via Python-list wrote:
> Dear List,
> 
> I would like to send out custom automated replies to email. In the future, I
> would like to be able to integrate nltk and fuzzy matching if necessary.
> 
> After some basic research I have a few options:
> 
>  1. Grapple with OpenEMM (interesting software, has python library, still 
> alive and kicking, a bit overkill for my use-case);
>  2. build on the examples in 'Automate the boring stuff';

>From briefly skimming the relevant section, it looks like this gives
some examples with smtplib and imaplib. That sounds like a good place to
start!

If you happen to have a server (VPS, Raspberry Pi, PC, whatever) running
a full MTA that you can forward your emails to, you could feed the
relevant messages to your script directly with the help of procmail,
rather than polling an IMAP server.

>  3. forget about it.
>  
> Please tell me about any possible alternatives I missed.
> 
> Kind regards,
> Brian
> 

-- 
https://mail.python.org/mailman/listinfo/python-list


RE: email automation

2018-10-23 Thread Ryan Johnson
Consider a web service API…Not really sure about where you want to evaluate 
your incoming emails, but perhaps MailChimp could help.
https://mailchimp.com/features/marketing-automation/
There are a bunch of ways to automate things with web services now, using 
Zapier.

https://mailchimp.com/features/marketing-automation/ 

Your question opens a big pandora’s box.

If you use web svc with API, either expect them to provide a library in your 
language, or expect them to send a structured data file over the internet, like 
json.
For web connection, use urllib.
For json use json module.
On windows:
py -m pip install urllib json

Sent from Mail for Windows 10

From: Brian Oney via Python-list
Sent: Monday, October 22, 2018 11:37 AM
To: python-list@python.org
Subject: email automation

Dear List,

I would like to send out custom automated replies to email. In the future, I
would like to be able to integrate nltk and fuzzy matching if necessary.

After some basic research I have a few options:

 1. Grapple with OpenEMM (interesting software, has python library, still 
alive and kicking, a bit overkill for my use-case);
 2. build on the examples in 'Automate the boring stuff';
 3. forget about it.
 
Please tell me about any possible alternatives I missed.

Kind regards,
Brian
-- 
https://mail.python.org/mailman/listinfo/python-list

-- 
https://mail.python.org/mailman/listinfo/python-list