Guest User

Untitled

a guest
Jul 23rd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. import MySQLdb
  2. import json
  3. import cherrypy
  4.  
  5. class Signups:
  6.  
  7. def index(self):
  8. '''
  9. This gets the number of user sign ups
  10. '''
  11. # form connection
  12. conn = MySQLdb.connect (host = "localhost",
  13. user = "root",
  14. passwd = "12345Aa",
  15. db = "geckoboard")
  16.  
  17. cursor = conn.cursor()
  18. # SQL Query
  19. cursor.execute(''' SELECT COUNT(1) AS Signups,
  20. DATE_FORMAT(JoinDate, "%Y-%m-%d") AS Date
  21. FROM users
  22. GROUP BY Date''')
  23.  
  24. # Get all data using fetchall()
  25. rows = cursor.fetchall()
  26.  
  27. # convert data to geckoboard format
  28. dict = { "item" :[x[0] for x in rows],
  29. "settings" : { "axisx" : [x[1] for x in rows],
  30. "axisy" : [0,100],
  31. "colour": "ff9900"}
  32.  
  33. }
  34.  
  35. # convert to json
  36. data_string = json.dumps(dict)
  37.  
  38. # test output
  39. return data_string
  40.  
  41. # Close connections
  42. cursor.close ()
  43. conn.close ()
  44.  
  45. index.exposed = True
  46.  
  47. import os.path
  48. tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf')
  49.  
  50. if __name__ == '__main__':
  51. cherrypy.quickstart(Signups(), config=tutconf)
  52. else:
  53. cherrypy.tree.mount(Signups(), config=tutconf)
Add Comment
Please, Sign In to add comment