Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from bottle import route, run, template
- import jsonpickle
- import mysql.connector
- import requests
- class Object:
- def to_JSON(self):
- return json.dumps(self, default=lambda o: o.__dict__,
- sort_keys=True, indent=4)
- def resultJSON(message,result):
- json=Object()
- json.message=message
- json.data=[]
- for row in result:
- rowd=Object()
- rowd.student_id=row[0]
- rowd.lat=row[1]
- rowd.long=row[2]
- json.data.append(rowd)
- return jsonpickle.encode(json,unpicklable=False)
- @route('/hello/:name')
- def index(name='World'):
- cnx=False
- result=[]
- try:
- cnx = mysql.connector.connect(user='Ralph2', password='CMT3313Ral!',
- host='Ralph2.db.11698469.hostedresource.com',
- database='Ralph2')
- cursor = cnx.cursor()
- cursor.execute("""
- SELECT * FROM StudentPosition
- """)
- result = cursor.fetchall()
- finally:
- if (cnx):
- return resultJSON("Successfully retrieved "+name,result)
- cnx.close()
- else:
- return resultJSON("Failed to retrieve data",result);
- ################################################################################
- @route('/login')
- def login():
- r = requests.get("http://buildapp.co.uk/StudentCloud/v/2/api/v1/?url=drive/files/-1")
- return r.content
- run(host='localhost', port=8082)
Add Comment
Please, Sign In to add comment