Besimplestudio commited on
Commit
cce596f
·
verified ·
1 Parent(s): b89187a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -28,7 +28,7 @@ def analyze_coloring_trends(search_query='adult coloring books', region='US'):
28
 
29
  for category in coloring_categories:
30
  try:
31
- print(f"Fetching data for category: {category}")
32
 
33
  # Build payload with extended timeframe to capture more trends
34
  pytrends.build_payload(
@@ -40,9 +40,10 @@ def analyze_coloring_trends(search_query='adult coloring books', region='US'):
40
 
41
  # Fetch related queries
42
  related_queries = pytrends.related_queries()
 
43
 
44
  # Ensure data exists for the category
45
- if related_queries and related_queries[category]['top'] is not None:
46
  for row in related_queries[category]['top'].itertuples():
47
  trending_keywords[row.query] += row.value
48
  results.append({
@@ -51,7 +52,7 @@ def analyze_coloring_trends(search_query='adult coloring books', region='US'):
51
  'category': category
52
  })
53
  else:
54
- print(f"No data for category: {category}")
55
 
56
  time.sleep(3) # Increase delay to avoid rate limiting
57
 
@@ -64,6 +65,7 @@ def analyze_coloring_trends(search_query='adult coloring books', region='US'):
64
 
65
  # If DataFrame is empty, handle the case gracefully
66
  if df.empty:
 
67
  return "No data available for the selected category in this region.", "", ""
68
 
69
  # Create bar chart visualization
 
28
 
29
  for category in coloring_categories:
30
  try:
31
+ print(f"Fetching data for category: {category} in region: {region}")
32
 
33
  # Build payload with extended timeframe to capture more trends
34
  pytrends.build_payload(
 
40
 
41
  # Fetch related queries
42
  related_queries = pytrends.related_queries()
43
+ print(f"Related queries for {category}: {related_queries}")
44
 
45
  # Ensure data exists for the category
46
+ if related_queries and related_queries.get(category, {}).get('top') is not None:
47
  for row in related_queries[category]['top'].itertuples():
48
  trending_keywords[row.query] += row.value
49
  results.append({
 
52
  'category': category
53
  })
54
  else:
55
+ print(f"No data for category: {category} in region: {region}")
56
 
57
  time.sleep(3) # Increase delay to avoid rate limiting
58
 
 
65
 
66
  # If DataFrame is empty, handle the case gracefully
67
  if df.empty:
68
+ print("No data available for the selected category in this region.")
69
  return "No data available for the selected category in this region.", "", ""
70
 
71
  # Create bar chart visualization