mikedbjones / longtrends

Package to download long-term Google Trends
https://pypi.org/project/longtrends
MIT License
14 stars 1 forks source link

Increase speed? #5

Open asdsadsaasd12312132 opened 11 months ago

asdsadsaasd12312132 commented 11 months ago

The script is taking 10 minutes to chart 2 years of data, which is too long. Is there any way to speed it up?

mikedbjones commented 11 months ago

Can you be any more specific? Code, keywords, environment, hardware, etc? This code normally takes a matter of seconds, so I imagine there is an external factor that's causing the long runtime, in which case I'll be unable to assist.

asdsadsaasd12312132 commented 11 months ago

This is my code. It tooks long for every keyword I use. I'm on WIndows 10 64 bit. My hardware should be strong enough. I have the latest i9 and 64 gb of RAM.

from longtrends import LongTrend
from datetime import date, datetime, timedelta
import matplotlib.pyplot as plt
import mplcursors
from matplotlib.widgets import Cursor

keyword = 'apples'

# Create LongTrend object
longtrend = LongTrend(
                      keyword=keyword,
                      start_date=datetime(2022, 1, 1),
                      end_date=datetime.now())        # use verbose=True for print output
# Build long-term trends
lt_built = longtrend.build()

# Plot
axlist = lt_built.plot(title=f"Google Trends: {longtrend.keyword}", figsize=(15, 3))
mplcursors.cursor(axlist) #annotation when clicking on point
cursor = Cursor(axlist, useblit=True, color='k', lw=0.6, ls='--') #crosshair

plt.show()

I have also issues where some parts of the chart are flat.

image

mikedbjones commented 11 months ago

I recommend you use some python timing functions to narrow down the problem. Ultimately, since longtrends simply scales pytrends outputs, the timing issue is likely to be with pytrends, or your plotting library. Without detailed information I cannot assist further.

asdsadsaasd12312132 commented 11 months ago

You said it only takes a few seconds for you. What code were you using?