Skip to content

Commit

Permalink
Custom update interval
Browse files Browse the repository at this point in the history
  • Loading branch information
elParaguayo committed Oct 2, 2016
1 parent 33b2171 commit bded171
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 78 deletions.
100 changes: 22 additions & 78 deletions default.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@
"ShowBookings", "ShowGoalscorer")
SETTINGS_NOTIFICATION_TIME = ("DisplayTime", )
SETTINGS_LEAGUES = ("watchedleagues", )
SETTING_REFRESH = ("RefreshTime", )

REFRESH_INTERVALS = (60, 90, 120, 150, 180, 300, 600, 900)

class SettingsMonitor(xbmc.Monitor):
'''Handler to checking when settings are updated and triggering an
Expand Down Expand Up @@ -128,6 +130,7 @@ def __init__(self):
self.DETAILED = -1
self.NOTIFY_TIME = -1
self.ADVANCED_NOTIFICATIONS = -1
self.REFRESH_TIME = 12

self.updated_needed = False

Expand Down Expand Up @@ -182,6 +185,9 @@ def getSettings(self):
if any(x in SETTINGS_NOTIFICATION_TIME for x in self.config._updated):
self.checkNotificationTime()

if any(x in SETTING_REFRESH for x in self.config._updated):
self.checkRefreshTime()

def checkNotificationTime(self):
'''Sets the length of time for which notifications should be
displayed.
Expand All @@ -198,6 +204,19 @@ def checkNotificationTime(self):
self.NOTIFY_TIME = n * 1000
self.queue.timeout = self.NOTIFY_TIME

def checkRefreshTime(self):
'''Sets the time required between updates'''
try:
idx = int(self.config.RefreshTime)
except ValueError:
idx = 0

interval = REFRESH_INTERVALS[idx]

debug("Update interval is now {} seconds.".format(interval))

self.REFRESH_TIME = interval / 5

def checkAlerts(self):
'''Setting is "True" when alerts are disabled.
'''
Expand Down Expand Up @@ -333,78 +352,6 @@ def checkMatch(self, match):
debug(u"Match needs processing... {}".format(repr(match)))
self.queue.add(match)

# if match.booking:
#
# # Should we show notification?
# if (self.SHOW_YELLOW and self.DETAILED):
# debug(u"yellow card: {}".format(match.LastYellowCard))
# try:
# yellow = u" {1} ({0})".format(*match.LastYellowCard)
# except AttributeError:
# yellow = None
# else:
# yellow = None
#
# if self.SHOW_YELLOW:
#
# self.Notify(u"YELLOW!{0}".format(yellow if yellow else u""),
# unicode(match),
# IMG_YELLOW,
# timeout=self.NOTIFY_TIME)
# debug(u"Yellow Card: {}, {}".format(match, yellow))
#
# if match.redcard:
#
# # Should we show notification?
# if (self.SHOW_RED and self.DETAILED):
# debug(u"red card: {}".format(match.LastRedCard))
# try:
# red = u" {1} ({0})".format(*match.LastRedCard)
# except AttributeError:
# red = None
# else:
# red = None
#
# if self.SHOW_RED:
#
# self.Notify(u"RED!{0}".format(red if red else u""),
# unicode(match),
# IMG_RED,
# timeout=self.NOTIFY_TIME)
# debug(u"Red Card: {}, {}".format(match, red))
#
# # Has there been a goal?
# if match.Goal:
#
# # Gooooooooooooooooooooooooooooollllllllllllllll!
#
# # Should we show goalscorer?
# if (self.SHOW_GOALSCORER and self.DETAILED):
# debug(u"goalscorer: {}".format(match.LastGoalScorer))
# try:
# scorer = u" {0}".format(match.LastGoalScorer[1])
# except AttributeError:
# scorer = None
# else:
# scorer = None
#
# self.Notify(u"GOAL!{0}".format(scorer if scorer else u""),
# unicode(match),
# IMG_GOAL,
# timeout=self.NOTIFY_TIME)
# debug(u"GOAL: {}, {}".format(match, scorer))
#
# # Has the status changed? e.g. kick-off, half-time, full-time?
# if match.StatusChanged:
#
# # Get the relevant status info
# info = STATUS_DICT.get(match.status, STATUS_DICT["Fixture"])
#
# # Send the notification
# self.Notify(info[0], unicode(match), info[1],
# timeout=self.NOTIFY_TIME)
# debug(u"STATUS: {0}".format(unicode(match)))

def checkTickers(self):
'''Tickers are not a class property because they are implemented by a
separate script.
Expand Down Expand Up @@ -458,8 +405,6 @@ def doUpdates(self):
Takes one argument:
self.matchdict: dictionary of leagues being watchedleagues
Returns updated dictionary
'''

ticker = u""
Expand Down Expand Up @@ -524,7 +469,7 @@ def run(self):
self.updated_needed = False

# If user wants alerts and we've reached our desired loop number...
if self.SHOW_ALERTS and not i:
if not i:

# Update our match dictionary and check for updates.
debug("Checking scores...")
Expand All @@ -540,9 +485,8 @@ def run(self):
#xbmc.sleep(5000)

# Increment our counter
# 12 x 5000 = 60,000 i.e. scores update every 1 minute
# Currently hard-coded - may look to change this.
i = (i + 1) % 12
# will equal 0 when we hit our desired refresh time.
i = (i + 1) % self.REFRESH_TIME


if __name__ == "__main__":
Expand Down
4 changes: 4 additions & 0 deletions resources/language/English/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ msgctxt "#32003"
msgid "Notification display time (secs)"
msgstr ""

msgctxt "#32004"
msgid "Update interval (secs)"
msgstr ""

#empty ids from 32003 through 32019

#settings script messages
Expand Down
1 change: 1 addition & 0 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<setting id="SetLeagues" label="32000" type="action" action="RunScript(service.bbclivefootballscores, mode=selectleague)" default="" />
<setting id="Alerts" label="32001" default="false" type="bool" />
<setting id="DisplayTime" label="32003" type="slider" range="1,1,20" option="int" default="2" />
<setting id="RefreshTime" label="32004" type="enum" values="60|90|120|150|180|300|600|900" default="0" />

<setting type="sep" />

Expand Down

0 comments on commit bded171

Please sign in to comment.