Re: Is there a Python module to parse a date like the 'date' command in Linux?

2023-06-01 Thread Mike Dewhirst

On 24/05/2023 6:00 pm, Mike Dewhirst wrote:

On 23/05/2023 7:16 pm, Chris Green wrote:

Mike Dewhirst  wrote:

[-- multipart/mixed, encoding 7bit, 22 lines --]

 [-- text/plain, encoding base64, charset: UTF-8, 16 lines --]

On 21/05/2023 5:53 am, Chris Green wrote:

I'm converting a bash script to python as it has become rather clumsy
in bash.

What is the use case?


A script I use to create diary entries, so it's very handy to be able
to give the date as 'yesterday' or 'friday'.


OK - I thought maybe baklabel might suit, but that delivers a day-name 
(backup filename prefix) for today or a given date


I have just refreshed baklabel on PyPI and upped it from my local svn 
server to github [1]


The changes include resolving ambiguous dates across locales eg USA vs 
Australia 5/6/2023 being detected as May in USA and June in Australia on 
the assumption that the user knows what is required.


[1] https://github.com/mdewhirst/baklabel





--
Signed email is an absolute defence against phishing. This email has
been signed with my private key. If you import my public key you can
automatically decrypt my signature and be sure it came from me. Your
email software can handle signing.


--
Signed email is an absolute defence against phishing. This email has
been signed with my private key. If you import my public key you can
automatically decrypt my signature and be sure it came from me. Your
email software can handle signing.



OpenPGP_signature
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there a Python module to parse a date like the 'date' command in Linux?

2023-05-24 Thread Mike Dewhirst

On 23/05/2023 7:16 pm, Chris Green wrote:

Mike Dewhirst  wrote:

[-- multipart/mixed, encoding 7bit, 22 lines --]

 [-- text/plain, encoding base64, charset: UTF-8, 16 lines --]

On 21/05/2023 5:53 am, Chris Green wrote:

I'm converting a bash script to python as it has become rather clumsy
in bash.

What is the use case?


A script I use to create diary entries, so it's very handy to be able
to give the date as 'yesterday' or 'friday'.


OK - I thought maybe baklabel might suit, but that delivers a day-name 
(backup filename prefix) for today or a given date







--
Signed email is an absolute defence against phishing. This email has
been signed with my private key. If you import my public key you can
automatically decrypt my signature and be sure it came from me. Your
email software can handle signing.



OpenPGP_signature
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there a Python module to parse a date like the 'date' command in Linux?

2023-05-23 Thread Alex Pinkney
On Tue, 23 May 2023, 17:25 Chris Green,  wrote:

> Mike Dewhirst  wrote:
> > [-- multipart/mixed, encoding 7bit, 22 lines --]
> >
> > [-- text/plain, encoding base64, charset: UTF-8, 16 lines --]
> >
> > On 21/05/2023 5:53 am, Chris Green wrote:
> > > I'm converting a bash script to python as it has become rather clumsy
> > > in bash.
> >
> > What is the use case?
> >
> A script I use to create diary entries, so it's very handy to be able
> to give the date as 'yesterday' or 'friday'.
>
> --
> Chris Green
> ·
> --
> https://mail.python.org/mailman/listinfo/python-list



Hi, you may find dateparser useful:
https://dateparser.readthedocs.io/en/latest/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there a Python module to parse a date like the 'date' command in Linux?

2023-05-23 Thread Chris Green
Mike Dewhirst  wrote:
> [-- multipart/mixed, encoding 7bit, 22 lines --]
> 
> [-- text/plain, encoding base64, charset: UTF-8, 16 lines --]
> 
> On 21/05/2023 5:53 am, Chris Green wrote:
> > I'm converting a bash script to python as it has become rather clumsy
> > in bash.
> 
> What is the use case?
> 
A script I use to create diary entries, so it's very handy to be able
to give the date as 'yesterday' or 'friday'.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there a Python module to parse a date like the 'date' command in Linux?

2023-05-22 Thread Mike Dewhirst

On 21/05/2023 5:53 am, Chris Green wrote:

I'm converting a bash script to python as it has become rather clumsy
in bash.


What is the use case?


However I have hit a problem with converting dates, the bash script
has:-

 dat=$(date --date "$1" +"%Y/%m/%d")

and this will accept almost anything reasonably sensible that can be
interpreted as a date, in particular it accepts things like "tomorrow",
"yesterday" and "next thursday".

Is there anything similar in Python or would I be better off simply
using os.system() to run date from the python program?




--
Signed email is an absolute defence against phishing. This email has
been signed with my private key. If you import my public key you can
automatically decrypt my signature and be sure it came from me. Your
email software can handle signing.



OpenPGP_signature
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there a Python module to parse a date like the 'date' command in Linux?

2023-05-22 Thread Tim Williams
On Mon, May 22, 2023 at 12:41 PM Mats Wichmann  wrote:

> On 5/20/23 13:53, Chris Green wrote:
> > I'm converting a bash script to python as it has become rather clumsy
> > in bash.
> >
> > However I have hit a problem with converting dates, the bash script
> > has:-
> >
> >  dat=$(date --date "$1" +"%Y/%m/%d")
> >
> > and this will accept almost anything reasonably sensible that can be
> > interpreted as a date, in particular it accepts things like "tomorrow",
> > "yesterday" and "next thursday".
> >
> > Is there anything similar in Python or would I be better off simply
> > using os.system() to run date from the python program?
> >
>
> in the standard library, datetime
>
> as an addon module, dateutil  (install as python-dateutil)
>
> Don't know if either are exactly what you want, but do take a look.
>
> --
> https://mail.python.org/mailman/listinfo/python-list


In particular,check out dateutil.parser.
parser — dateutil 2.8.2 documentation


parser


This module offers a generic date/time string parser which is able to parse
most known formats to represent a date and/or time.

This module attempts to be forgiving with regards to unlikely input
formats, returning a datetime object even for dates which are ambiguous. If
an element of a date/time stamp is omitted, the following rules are applied:
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there a Python module to parse a date like the 'date' command in Linux?

2023-05-22 Thread Mats Wichmann

On 5/20/23 13:53, Chris Green wrote:

I'm converting a bash script to python as it has become rather clumsy
in bash.

However I have hit a problem with converting dates, the bash script
has:-

 dat=$(date --date "$1" +"%Y/%m/%d")

and this will accept almost anything reasonably sensible that can be
interpreted as a date, in particular it accepts things like "tomorrow",
"yesterday" and "next thursday".

Is there anything similar in Python or would I be better off simply
using os.system() to run date from the python program?



in the standard library, datetime

as an addon module, dateutil  (install as python-dateutil)

Don't know if either are exactly what you want, but do take a look.

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