Advertisement
Guest User

newwwwwwwwwwww

a guest
Jan 12th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.31 KB | None | 0 0
  1. from flask import Flask, url_for, request, json, jsonify
  2. import mysql.connector
  3. app = Flask(__name__)
  4.  
  5.  
  6. @app.route('/') ##A good old welcome message
  7. def api_root():
  8.     return 'Welcome'
  9.  
  10. @app.route('/api', methods=['POST']) ###set the route to /api and methods
  11. ### to post because we don't need to GET anything.
  12. def jsontest(): ##We set it up to only recieve json or it outputs a error.
  13.         if request.headers['Content-Type'] == 'application/json':
  14.         conn = mysql.connector.connect(host='localhost',
  15.                                        database='testdb',
  16.                                        user='root',
  17.                                        password='secret')
  18.         x = conn.cursor()
  19.                 request.get_data()
  20.                 output = (request.json)
  21.                 with open("Jannick.txt", "w") as text_file:
  22.                         text_file.write(output['IP'])
  23. #                print output[1]
  24. #                return output['email']
  25. #                return output['IP']
  26.         mysqlIP = output['IP']
  27.         mysqlemail = output['email']
  28.         mysqlRDP = output['RDP']
  29.         x.execute ("""UPDATE IP set email =%s, RDP =%s WHERE IP =%s""",(mysqlemail,mysqlRDP,mysqlIP))
  30.         conn.commit()
  31.         return "string ok"
  32.         else:
  33.                 print "fuck"
  34.  
  35.  
  36. if __name__ == '__main__':
  37.  
  38.         app.run(debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement