Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import print_function
- from flask import Flask, request, jsonify, render_template
- from werkzeug import secure_filename
- from flask_cors import CORS
- from random import randint
- try:
- import pymysql
- pymysql.install_as_MySQLdb()
- except ImportError:
- pass
- import MySQLdb
- import json
- 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,
- "Attachments":"https://s1.amazon.com/jd-upload/DataJD.docx"}]
- app = flask.Flask(__name__)
- CORS(app)
- app.config["DEBUG"] = True
- # do validation and checks before insert
- def validate_string(val):
- if val != None:
- if type(val) is int:
- #for x in val:
- # print(x)
- return str(val).encode('utf-8')
- else:
- return val
- @app.route("/uploaddata", methods=['POST'])
- def upload_file():
- db = MySQLdb.connect("localhost", "root", "Mysql1!","test")
- cur = db.cursor()
- for i, item in enumerate(a):
- JD_Name= validate_string(item.get("JD_Name", None))
- ID= validate_string(item.get("ID", None))
- No_of_Position= validate_string(item.get("No_of_Position", None))
- Skill_Sets= validate_string(item.get("Skill_Sets", None))
- Created_Date= validate_string(item.get("Created_Date", None))
- Received_profile= validate_string(item.get("Received_profile", None))
- Interview_completed= validate_string(item.get("Interview_completed", None))
- Yet_to_schedule= validate_string(item.get("Yet_to_schedule", None))
- Attachments= validate_string(item.get("Attachments", None))
- 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))
- con.commit()
- con.close()
- return 'file uploaded successfully'
- app.run()
Add Comment
Please, Sign In to add comment