Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

API class is now capable of parsing urls composed of arbitrary /<tag>…

…/<value>/ pairs. Next step is to hook up a database.
  • Loading branch information...
commit 945c3306e3da8d3644681a02e8af33691b17b726 1 parent aa01cb5
@MusikPolice authored
Showing with 19 additions and 27 deletions.
  1. +19 −27 musik.py
View
46 musik.py
@@ -1,40 +1,32 @@
import cherrypy
+import re
-class Albums:
- def index(self):
- return "A list of all known albums"
- index.exposed = True
+# defines an api with a dynamic url scheme composed of /<tag>/<value>/ pairs
+# these pairs are assembled into an SQL query. Each term is combined with the AND operator.
+# unknown <tag> elements are ignored.
+class API:
- def default(self, album):
- return "Album page for %s" %album
- default.exposed = True
+ def default(self, *params):
+ #TODO: pull all available tags from the database so this regex is dynamic and allows any tag
+ regex = re.compile("genre|artist|album|track")
+ #TODO: instead of a string, assemble an SQL query
+ str = ""
+ for index in xrange(0, len(params), 2):
+ if regex.match(params[index]):
+ str += params[index] + ": "
-class Artists:
- albums = Albums()
-
- def index(self):
- return "A list of all known artists"
- index.exposed = True
+ if len(params) > (index + 1):
+ str += params[index + 1] + "<br />"
+ else:
+ str += "* <br />"
- def default(self, artist):
- return "Artist page for %s" %artist
+ return str
default.exposed = True
-
-# defines the restful api that all client applications use
-class Api:
- artists = Artists()
- albums = Albums()
-
- def index(self):
- return "Welcome to the API"
- index.exposed = True
-
-
# defines the web application that is the default client
class Musik:
- api = Api()
+ api = API()
def index(self):
return "Welcome to the Application"
Please sign in to comment.
Something went wrong with that request. Please try again.