Guest User

Untitled

a guest
Nov 19th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. from __future__ import print_function
  2. from flask import Flask, request, jsonify, render_template
  3. from werkzeug import secure_filename
  4. from flask_cors import CORS
  5. from random import randint
  6. try:
  7. import pymysql
  8. pymysql.install_as_MySQLdb()
  9. except ImportError:
  10. pass
  11. import MySQLdb
  12. import json
  13. a= [{"JD_Name": "Data Engineer","ID":10,"No_of_Position":5,"Skill_Sets":"Big Data, Python, Hadoop, MapReduce", "Created_Date":"2018-06-30","Received_profile":25,"Interview_completed":4,"Yet_to_schedule":10,
  14. "Attachments":"https://s1.amazon.com/jd-upload/DataJD.docx"}]
  15.  
  16. app = flask.Flask(__name__)
  17. CORS(app)
  18. app.config["DEBUG"] = True
  19.  
  20. # do validation and checks before insert
  21. def validate_string(val):
  22. if val != None:
  23. if type(val) is int:
  24. #for x in val:
  25. # print(x)
  26. return str(val).encode('utf-8')
  27. else:
  28. return val
  29.  
  30. @app.route("/uploaddata", methods=['POST'])
  31. def upload_file():
  32. db = MySQLdb.connect("localhost", "root", "Mysql1!","test")
  33. cur = db.cursor()
  34. for i, item in enumerate(a):
  35. JD_Name= validate_string(item.get("JD_Name", None))
  36. ID= validate_string(item.get("ID", None))
  37. No_of_Position= validate_string(item.get("No_of_Position", None))
  38. Skill_Sets= validate_string(item.get("Skill_Sets", None))
  39. Created_Date= validate_string(item.get("Created_Date", None))
  40. Received_profile= validate_string(item.get("Received_profile", None))
  41. Interview_completed= validate_string(item.get("Interview_completed", None))
  42. Yet_to_schedule= validate_string(item.get("Yet_to_schedule", None))
  43. Attachments= validate_string(item.get("Attachments", None))
  44.  
  45. cursor.execute("INSERT INTO addjd1 (JD_Name, ID, No_of_Position, Skill_Sets, Created_Date, Received_profile, Interview_completed, Yet_to_schedule, Attachments) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)", (JD_Name, ID, No_of_Position, Skill_Sets, Created_Date, Received_profile, Interview_completed, Yet_to_schedule, Attachments))
  46. con.commit()
  47. con.close()
  48. return 'file uploaded successfully'
  49.  
  50. app.run()
Add Comment
Please, Sign In to add comment