Skip to content

Commit

Permalink
Gartner update (#2878)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjison authored Dec 7, 2024
1 parent c8d5006 commit 51b48df
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions apps/gartnernews/gartner_news.star
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Description: Display Gartner News Feed.
Author: Robert Ison
"""

load("cache.star", "cache") #Caching
load("encoding/base64.star", "base64") #Used to read encoded image
load("http.star", "http") #HTTP Client
load("render.star", "render")
Expand All @@ -24,23 +23,18 @@ def main(config):
The display inforamtion for the Tidbyt
"""
GARTNER_RSS_URL = "https://www.gartner.com/en/newsroom/rss"

number_of_items = 0
seconds_xml_valid_for = 6 * 60 * 60 #6 hours

xml_body = cache.get(GARTNER_RSS_URL)
if xml_body == None:
gartner_xml = http.get(GARTNER_RSS_URL, headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36", "Accept": "text/html"})

if gartner_xml.status_code == 200:
xml_body = gartner_xml.body()
number_of_items = xml_body.count("<item>")
gartner_xml = http.get(GARTNER_RSS_URL, headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Safari/605.1.1", "Accept": "text/html,application/xhtml+xml,application/xml"}, ttl_seconds = seconds_xml_valid_for)

# TODO: Determine if this cache call can be converted to the new HTTP cache.
cache.set(GARTNER_RSS_URL, xml_body, ttl_seconds = seconds_xml_valid_for)
else:
number_of_items = 0
else:
if gartner_xml.status_code == 200:
xml_body = gartner_xml.body()
number_of_items = xml_body.count("<item>")
else:
xml_body = None
number_of_items = 0

if number_of_items == 0:
return []
Expand All @@ -53,11 +47,7 @@ def main(config):
current_query = "//item[" + str(i) + "]/title"
current_title = xpath.loads(xml_body).query(current_query)
current_query = "//item[" + str(i) + "]/pubDate"
#current_pub_date = xpath.loads(xml_body).query(current_query)
#current_date = get_pub_date(current_pub_date, timezone)

#current_item_time = time.parse_time(current_time_stamp).in_location(timezone) + get_local_offset(config)
#date_diff = get_local_time(config) - current_date
if len(display_text[marquee_row]) + len(current_title) > text_limit:
if marquee_row < len(display_text) - 1:
marquee_row = marquee_row + 1
Expand Down Expand Up @@ -136,7 +126,7 @@ def get_schema():
id = "scroll",
name = "Scroll",
desc = "Scroll Speed",
icon = "stopwatch",
icon = "scroll",
options = scroll_speed_options,
default = scroll_speed_options[0].value,
),
Expand Down

0 comments on commit 51b48df

Please sign in to comment.