Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ Feature request ] Add getPublishedDate method #2

Closed
trueToastedCode opened this issue Aug 23, 2022 · 3 comments
Closed

[ Feature request ] Add getPublishedDate method #2

trueToastedCode opened this issue Aug 23, 2022 · 3 comments

Comments

@trueToastedCode
Copy link

The preview url also contains the published date. Could be extracted like that:

def getPublishedDate(self):
    previewUrl = self.getPreviewURL()
    match = re.search('\d{4}/\d{2}/\d{2}/\d{2}/\d{2}', previewUrl)
    if not match:
        return
    parts = match.group().split('/')
    return datetime(int(parts[0]), int(parts[1]), int(parts[2]),
                    int(parts[3]), int(parts[4]), tzinfo=timezone.utc)
@Lukas0025
Copy link
Owner

Lukas0025 commented Aug 23, 2022 via email

@trueToastedCode
Copy link
Author

trueToastedCode commented Aug 24, 2022

To be added in next commit. Dne út 23. 8. 2022 21:54 uživatel trueToastedCode @.> napsal:

The preview url also contains the published date. Could be extracted like that: def getPublishedDate(self): previewUrl = self.getPreviewURL() match = re.search('\d{4}/\d{2}/\d{2}/\d{2}/\d{2}', previewUrl) if not match: return parts = match.group().split('/') return datetime(int(parts[0]), int(parts[1]), int(parts[2]), int(parts[3]), int(parts[4]), tzinfo=timezone.utc) — Reply to this email directly, view it on GitHub <#2>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACM7NGLHY4LJOWAV2UYP2JLV2UUARANCNFSM57MYNTMA . You are receiving this because you are subscribed to this thread.Message ID: @.
>

I noticed that in some cases the preview url actually doesn't include the hour and minute. An adopted version would be:

def getPublishedDate(self):
    preview_url = self.getPreviewUrl()
    #  year / month / day / hour / minute
    match = re.search('\d{4}/\d{2}/\d{2}/\d{2}/\d{2}', preview_url)
    if match:
        parts = match.group().split('/')
        return datetime.datetime(int(parts[0]), int(parts[1]), int(parts[2]),
                        int(parts[3]), int(parts[4]), tzinfo=datetime.timezone.utc)
    #  year / month / day
    match = re.search('\d{4}/\d{2}/\d{2}', preview_url)
    if match:
        parts = match.group().split('/')
        return datetime.datetime(int(parts[0]), int(parts[1]), int(parts[2]),
                        tzinfo=datetime.timezone.utc)

@Lukas0025
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants