Skip to content

Commit

Permalink
Update india_news to exclude market/cricket news and added SSH keys t…
Browse files Browse the repository at this point in the history
…o .gitignore
  • Loading branch information
vipulchhajer committed Jan 22, 2025
1 parent 4e5c304 commit 23a6c50
Showing 1 changed file with 42 additions and 6 deletions.
48 changes: 42 additions & 6 deletions apps/indianews/india_news.star
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def main(config):

#intialize headline randomizer
random.seed(time.now().unix // 60)
shift = random.number(0, 95)
shift = random.number(0, 80)

#Display error if no API found
if DEFAULT_API == None:
Expand Down Expand Up @@ -58,14 +58,50 @@ def main(config):
if rep.status_code != 200:
title = ["Error getting data!!!!", "", "", ""]
else:
#get top 3 newest headlines
#get top 3 newest headlines, excluding market/industry news
title = []
for i in range(4):
j = i + shift
title.append((rep.json()["articles"][j]["title"]).split(" - ")[0])
excluded_patterns = [
"economictimes.indiatimes.com/markets/",
"livemint.com/industry/",
"www.livemint.com/companies/",
"economictimes.indiatimes.com/wealth/",
"economictimes.indiatimes.com/industry/",
"timesofindia.indiatimes.com/city/ahmedabad/",
"timesofindia.indiatimes.com/city/bengaluru/",
"timesofindia.indiatimes.com/sports/",
"economictimes.indiatimes.com/news/sports/",
"timesofindia.indiatimes.com/tv/",
"timesofindia.indiatimes.com/education/",
"timesofindia.indiatimes.com/entertainment/english/hollywood/"
]
max_articles = len(rep.json()["articles"])
for j in range(max_articles):
if len(title) >= 4:
break

article = rep.json()["articles"][(j + shift) % max_articles]
article_url = article["url"]
article_title = article["title"].split(" - ")[0]

# Check if URL contains any excluded patterns
should_exclude = False
for pattern in excluded_patterns:
if pattern in article_url:
should_exclude = True
break

if not should_exclude:
title.append(article_title)

# If we don't have enough headlines after filtering, pad with empty strings
for _ in range(4 - len(title)):
title.append("")

#format strings so they are all the same length (leads to better scrolling)
max_len = max([len(x) for x in title])
lengths = []
for x in title:
lengths.append(len(x))
max_len = max(lengths)

#add padding to shorter titles
for i, x in enumerate(title):
Expand Down

0 comments on commit 23a6c50

Please sign in to comment.