Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added fetchers for now next and previous chart

  • Loading branch information...
commit 5ccce4712bd17237a0408d2e70d4cb97fbaee33c 1 parent 1eabfae
Ben Fields gearmonkey authored
Showing with 51 additions and 1 deletion.
  1. +51 −1 src/chart.py
52 src/chart.py
View
@@ -1,3 +1,4 @@
+import logging
from entity import *
CHARTS = {
@@ -22,6 +23,8 @@
'downloads daily high flyers': '2960402fc260409c8bcd75b00d8dc4c8'
}
+log = logging.getLogger(__name__)
+
class Chart(Entity):
"""
wraps the chart entity type as described at http://developer.musicmetric.com/charts.html
@@ -51,4 +54,51 @@ def __init__(self, chartUUID):
for key, val in self.response.items():
if key != "data":
setattr(self, key, val)
-
+
+ def next(self):
+ """
+ fetch the chart identified by this chart's next_id attribute
+ if the next_id is either null or not present for this chart return None
+ returns the new chart instance on sucess"""
+ try:
+ if self.next_id:
+ return Chart(self.next_id)
+ else:
+ log.debug('attempted to get next chart, but none was found')
+ return
+ except AttributeError:
+ #chart does not implement next pointer
+ log.debug('attempted to get next chart from a chart without a next attribute')
+ return None
+
+ def previous(self):
+ """
+ fetch the chart identified by this chart's previous_id attribute
+ if the previous_id is either null or not present for this chart return None
+ returns the new chart instance on sucess"""
+ try:
+ if self.previous_id:
+ return Chart(self.previous_id)
+ else:
+ log.debug('attempted to get previous chart, but none was found')
+ return
+ except AttributeError:
+ #chart does not implement next pointer
+ log.debug('attempted to get previous chart from a chart without a previous attribute')
+ return None
+
+ def now(self):
+ """
+ fetch the chart identified by this chart's now_id attribute
+ if the now_id is either null or not present for this chart return None
+ returns the new chart instance on sucess"""
+ try:
+ if self.now_id:
+ return Chart(self.now_id)
+ else:
+ log.debug('attempted to get current chart, but none was found')
+ return
+ except AttributeError:
+ #chart does not implement next pointer
+ log.debug('attempted to get current ("now") chart from a chart without a now attribute')
+ return None
Please sign in to comment.
Something went wrong with that request. Please try again.