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

Gartner update #2878

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading