Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask, url_for, request, json, jsonify
- import mysql.connector
- app = Flask(__name__)
- @app.route('/') ##A good old welcome message
- def api_root():
- return 'Welcome'
- @app.route('/api', methods=['POST']) ###set the route to /api and methods
- ### to post because we don't need to GET anything.
- def jsontest(): ##We set it up to only recieve json or it outputs a error.
- if request.headers['Content-Type'] == 'application/json':
- conn = mysql.connector.connect(host='localhost',
- database='testdb',
- user='root',
- password='secret')
- x = conn.cursor()
- request.get_data()
- output = (request.json)
- with open("Jannick.txt", "w") as text_file:
- text_file.write(output['IP'])
- # print output[1]
- # return output['email']
- # return output['IP']
- mysqlIP = output['IP']
- mysqlemail = output['email']
- mysqlRDP = output['RDP']
- x.execute ("""UPDATE IP set email =%s, RDP =%s WHERE IP =%s""",(mysqlemail,mysqlRDP,mysqlIP))
- conn.commit()
- return "string ok"
- else:
- print "fuck"
- if __name__ == '__main__':
- app.run(debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement