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

Previous date field is not filled #91

Open
LithosphereRocketry opened this issue Sep 21, 2023 · 3 comments
Open

Previous date field is not filled #91

LithosphereRocketry opened this issue Sep 21, 2023 · 3 comments

Comments

@LithosphereRocketry
Copy link

I'm trying to retrieve chart data for consecutive weeks, and I have some basic test code that looks like this:

import billboard

chart = billboard.ChartData('hot-100', date='2019-11-09')

print(chart)
print(chart.previousDate)

The correct chart is retrieved, but the previousDate field is always None. This is true whether I query for a specific date or leave it as the default latest chart.

@johnwmillr
Copy link
Collaborator

Looks like this is a known issue.

It doesn't look like the Billboard page provides a link to a previous or next chart date anymore. Am I missing one of those links on this page?

@LithosphereRocketry
Copy link
Author

I didn't realize that was deprecated - apologies! Is there a new recommended way to iterate through charts over time? Should I just de-format and re-format the date a week earlier?

@johnwmillr
Copy link
Collaborator

No need to apologize! I didn't realize it was deprecated till I dug into the code.

I think manually iterating through the dates you're interested in is your best bet. Here's an example from ChatGPT of how you could do it:

import datetime

def iterate_dates_in_month(year, month):
    # Create a date object for the first day of the month
    current_date = datetime.date(year, month, 1)

    # Calculate the last day of the month
    last_day = (current_date.replace(month=current_date.month % 12 + 1, day=1) - datetime.timedelta(days=1))

    # Iterate through the dates in the month
    while current_date <= last_day:
        yield current_date
        current_date += datetime.timedelta(days=1)

# Example usage:
import billboard


year = 2023
month = 9
for date in iterate_dates_in_month(year, month):
    print(date)
    chart = billboard.ChartData('hot-100', date=date)
    print(chart)

What do you think?

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