__init__.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. #!/usr/bin/python3
  2. from flask import Flask
  3. from flask_restful import Resource, Api
  4. from bson import json_util
  5. import json
  6. #import pymysql
  7. app = Flask(__name__)
  8. api = Api(app)
  9. #class Database:
  10. # def __init__(self):
  11. # host = "127.0.0.1"
  12. # user = "bus"
  13. # password = ""
  14. # db = "busdb"
  15. #
  16. # #self.con = pymysql.connect(host=host, user=user, db=db, cursorclass=pymysql.cursors.DictCursor)
  17. # #self.cur = self.con.cursor()
  18. #
  19. # def ok(self):
  20. # #self.cur.execute("select rulename from rule_class where id = %s", 1)
  21. # #res = self.cur.fetchall()
  22. # #return res
  23. # return {}
  24. #
  25. #
  26. #
  27. ##from app import routes
  28. #
  29. #class Card(Resource):
  30. # def get(self, cardid = None):
  31. #
  32. # db = Database()
  33. # db.cur.execute("select logical_card_id, " \
  34. # "mag_token, rfid_token, comment, " \
  35. # "userid, issuetype, "\
  36. # "issued, lastused, firstused, " \
  37. # "active, deactivated, group_id " \
  38. # "from user_card " \
  39. # "where logical_card_id = %s", cardid)
  40. # res = db.cur.fetchall()
  41. # print(res)
  42. # if len(res)>0:
  43. # s = json.dumps(res[0], default=json_util.default)
  44. # return json.loads(s)
  45. # return {"msg":"no card found", "param":cardid}
  46. #
  47. # def delete(self):
  48. # return {"msg":"delete card not implemented"}
  49. # def put(self):
  50. # return {"msg":"put/update card not implemented"}
  51. # def post(self):
  52. # return {"msg":"post/insert card not implemented"}
  53. #
  54. #class Pass(Resource):
  55. # def get(self, passid = None):
  56. #
  57. # db = Database()
  58. # db.cur.execute("select " \
  59. # "user_pass_id, logical_card_id, " \
  60. # "issued, activated, deactivated, " \
  61. # "firstused, lastused, " \
  62. # "nrides_orig, nrides_remain, " \
  63. # "nday_orig, nday_expiration, " \
  64. # " active, expired, " \
  65. # "rule, queue_order, " \
  66. # "comment, paytype " \
  67. # "from user_pass where user_pass_id = %s",
  68. # passid)
  69. # res = db.cur.fetchall()
  70. # print(res)
  71. # if len(res)>0:
  72. # s = json.dumps(res[0], default=json_util.default)
  73. # return json.loads(s)
  74. # return {"msg":"pass not found", "param":passid}
  75. #
  76. # def delete(self):
  77. # return {"msg":"delete pass not implemented"}
  78. # def put(self):
  79. # return {"msg":"put/update pass not implemented"}
  80. # def post(self):
  81. # return {"msg":"post/insert pass not implemented"}
  82. #
  83. #class User(Resource):
  84. # def get(self, userid = None):
  85. #
  86. # db = Database()
  87. # db.cur.execute("select " \
  88. # "username, userid, comment, " \
  89. # "first_name, last_name, phone, email, " \
  90. # "address, city, state, zip, created, active, " \
  91. # "passwordhash, " \
  92. # "shipping_address, shipping_city, shipping_state, shipping_zip, " \
  93. # "shipping_country_code, shipping_country_name, " \
  94. # "reset_attempts " \
  95. # "from users where userid = %s",
  96. # userid)
  97. # res = db.cur.fetchall()
  98. # print(res)
  99. # if len(res)>0:
  100. # s = json.dumps(res[0], default=json_util.default)
  101. # return json.loads(s)
  102. # return {"msg":"user not found", "param":passid}
  103. #
  104. #
  105. # def delete(self):
  106. # return {"msg":"delete user not implemented"}
  107. # def put(self):
  108. # return {"msg":"put/update user not implemented"}
  109. # def post(self):
  110. # return {"msg":"post/insert user not implemented"}
  111. #
  112. #class Group(Resource):
  113. # def get(self):
  114. # return {"msg":"get group not implemented"}
  115. # def delete(self):
  116. # return {"msg":"delete group not implemented"}
  117. # def put(self):
  118. # return {"msg":"put/update group not implemented"}
  119. # def post(self):
  120. # return {"msg":"post/insert group not implemented"}
  121. #
  122. #class PassOption(Resource):
  123. # def get(self):
  124. # return {"msg":"get passoption not implemented"}
  125. # def delete(self):
  126. # return {"msg":"delete passoption not implemented"}
  127. # def put(self):
  128. # return {"msg":"put/update passoption not implemented"}
  129. # def post(self):
  130. # return {"msg":"post/insert passoption not implemented"}
  131. #
  132. #class Rule(Resource):
  133. # def get(self):
  134. # return {"msg":"get rule not implemented"}
  135. # def delete(self):
  136. # return {"msg":"delete rule not implemented"}
  137. # def put(self):
  138. # return {"msg":"put/update rule not implemented"}
  139. # def post(self):
  140. # return {"msg":"post/insert rule not implemented"}
  141. #
  142. #
  143. ### Admin related
  144. ###
  145. #
  146. #class AdminUser(Resource):
  147. # def get(self):
  148. # return {"msg":"get adminuser not implemented"}
  149. # def delete(self):
  150. # return {"msg":"delete adminuser not implemented"}
  151. # def put(self):
  152. # return {"msg":"put/update adminuser not implemented"}
  153. # def post(self):
  154. # return {"msg":"post/insert adminuser not implemented"}
  155. #
  156. #class AdminGroup(Resource):
  157. # def get(self):
  158. # return {"msg":"get admingroup not implemented"}
  159. # def delete(self):
  160. # return {"msg":"delete admingroup not implemented"}
  161. # def put(self):
  162. # return {"msg":"put/update admingroup not implemented"}
  163. # def post(self):
  164. # return {"msg":"post/insert admingroup not implemented"}
  165. #
  166. #class Driver(Resource):
  167. # def get(self):
  168. # return {"msg":"get driver not implemented"}
  169. # def delete(self):
  170. # return {"msg":"delete driver not implemented"}
  171. # def put(self):
  172. # return {"msg":"put/update driver not implemented"}
  173. # def post(self):
  174. # return {"msg":"post/insert driver not implemented"}
  175. #
  176. #class Paddle(Resource):
  177. # def get(self):
  178. # return {"msg":"get paddle not implemented"}
  179. # def delete(self):
  180. # return {"msg":"delete paddle not implemented"}
  181. # def put(self):
  182. # return {"msg":"put/update paddle not implemented"}
  183. # def post(self):
  184. # return {"msg":"post/insert paddle not implemented"}
  185. #
  186. #class Bus(Resource):
  187. # def get(self):
  188. # return {"msg":"get bus not implemented"}
  189. # def delete(self):
  190. # return {"msg":"delete bus not implemented"}
  191. # def put(self):
  192. # return {"msg":"put/update bus not implemented"}
  193. # def post(self):
  194. # return {"msg":"post/insert bus not implemented"}
  195. #
  196. #
  197. from app import routes
  198. #
  199. #api.add_resource(Card, "/api/v1/card/", "/api/v1/card/<int:cardid>")
  200. #api.add_resource(Pass, "/api/v1/pass/", "/api/v1/pass/<int:passid>")
  201. #api.add_resource(User, "/api/v1/user/", "/api/v1/user/<int:userid>")
  202. #api.add_resource(Group, "/api/v1/group/", "/api/v1/group/<int:groupid>")
  203. #api.add_resource(PassOption, "/api/v1/passoption/", "/api/v1/passoption/<int:passoptionid>")
  204. #api.add_resource(Rule, "/api/v1/rule/", "/api/v1/rule/<int:ruleid>")
  205. #
  206. if __name__ == '__main__':
  207. app.run(debug=True)