Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask,request,flash
- from flask import jsonify # <- jsonify instead of json
- from werkzeug import secure_filename
- from flask_pymongo import PyMongo
- from PIL import Image, ImageDraw
- import os
- _name_ = "_main_"
- app = Flask(_name_)
- from pymongo import MongoClient
- client = MongoClient()
- client = MongoClient('localhost', 27017)
- db = client.test_database
- collection = db.test_collection
- profiles = db.profiles
- contacts = db.contacts
- shared = db.shared #who you've shared resumes with
- requested = db.requested #who you've requested to see resumes of
- os.makedirs(os.path.join(app.instance_path, 'files'), exist_ok=True)
- #requesting a resume?
- #seeing who you've shared resume with/who's shared with you
- @app.route("/createAccount", methods=['POST'])
- def create():
- email = request.form['email']
- if(profiles.find({"email": email}).count() == 0):
- liprofile = request.form['liprofile']
- phone = request.form['phone']
- fname = request.form['fname']
- lname = request.form['lname']
- pfname = request.form['pfname']
- password = request.form['password']
- user = {"phone": phone, "email": email, "fname": fname,
- "lname":lname, "pfname":pfname, "liprofile":liprofile, 'password':password}
- profile_id = profiles.insert_one(user).inserted_id
- contact = {"email": email, "emails": []}
- contacts.insert_one(contact)
- sharedd = {"email": email, "emails": []}
- shared.insert_one(sharedd)
- requestedd = {"email": email, "emails": []}
- requested.insert_one(requestedd)
- return jsonify(str(profile_id))
- else:
- return "Email already taken"
- @app.route("/shareResume", methods=['POST'])
- def shareResume():
- email1 = request.form['emailOrigin']
- email2 = request.form['emailFriend']
- result = shared.find_one({"email": email1})
- if(email2 in result['emails']):
- return "Already shared"
- if(len(result['emails']) == 0):
- templist = [email2]
- result['emails'] = templist
- else:
- result['emails'].append(email2)
- shared.update({"email": email1}, result)
- return jsonify("Success")
- #@app.route("/requestResume", methods=['POST'])
- @app.route("/createQR", methods=['POST'])
- def createQR():
- email = request.form['email']
- return jsonify(email)
- @app.route("/getAccount", methods=['POST'])
- def getAccount():
- email1 = request.form['emailOrigin']
- email2 = request.form['emailFriend']
- result = profiles.find_one({"email": email2})
- result.pop('_id')
- result2 = shared.find_one({"email": email2})
- if(email1 in result2['emails']):
- result['Resume'] = "http://0.0.0.0:8000/instance/files/"+email.replace("@", "")+".pdf"
- return jsonify(result)
- @app.route("/addContact", methods=['POST'])
- def addContact():
- email1 = request.form['emailOrigin']
- email2 = request.form['emailFriend']
- result = contacts.find_one({"email": email1})
- if(email2 in result['emails']):
- return "Already friends"
- if(len(result['emails']) == 0):
- templist = [email2]
- result['emails'] = templist
- else:
- result['emails'].append(email2)
- contacts.update({"email": email1}, result)
- result = contacts.find_one({"email": email2})
- if(len(result['emails']) == 0):
- templist = [email1]
- result['emails'] = templist
- else:
- result['emails'].append(email1)
- contacts.update({"email":email2}, result)
- return jsonify("Success")
- @app.route("/getContacts", methods=['POST'])
- def getContacts():
- email = request.form['email']
- result = contacts.find_one({"email": email})
- contactslist = []
- for contact in result["emails"]:
- profile = profiles.find_one({"email": str(contact)})
- profile.pop('_id')
- contactslist.append(profile)
- return jsonify(contactslist)
- @app.route("/getShared", methods=['POST'])
- def getShared():
- email = request.form['email']
- result = shared.find_one({"email": email})
- sharedlist = []
- for sharedd in result["emails"]:
- profile = profiles.find_one({"email": str(sharedd)})
- profile.pop('_id')
- sharedlist.append(profile)
- return jsonify(sharedlist)
- @app.route("/getReceived", methods=['POST'])
- def getReceived():
- email = request.form['email']
- receivedlist = []
- for e in shared.find():
- for f in e['emails']:
- if(f == email):
- profile = profiles.find_one({"email":e['email']})
- profile.pop('_id')
- receivedlist.append(profile)
- return jsonify(receivedlist)
- @app.route("/signIn", methods=['POST'])
- def signIn():
- email = request.form['email']
- if(profiles.find({"email": email}).count() == 0):
- return "Email not found."
- result = profiles.find_one({'email': email})
- password = request.form['password']
- if(result['password'] != password):
- return "Incorrect password."
- result.pop('_id')
- return jsonify(result)
- @app.route('/uploadResume', methods = ['GET', 'POST'])
- def uploadResume():
- if request.method == 'POST':
- email = request.form["email"]
- f = request.files['file']
- # when saving the file
- f.save(os.path.join(app.instance_path, 'files', secure_filename(email)+".pdf"))
- return jsonify('file uploaded successfully')
- @app.route('/uploadCard', methods = ['GET', 'POST'])
- def uploadCard():
- if request.method == 'POST':
- email = request.form["email"]
- f = request.files['file']
- # when saving the file
- f.save(os.path.join(app.instance_path, 'cards', secure_filename(email)+".jpg"))
- return 'file uploaded successfully'
- #matt's fancy thing gives a dictionary in
- #email = in['email'];
- #if(profiles.find({"email": email}).count() == 0)
- #{
- # liprofile = in['liprofile']
- # phone = in['phone']
- # fname = in['fname']
- # lname = in['lname']
- # pfname = in['pfname']
- # password = in['password']
- # user = {"phone": phone, "email": email, "fname": fname,
- # "lname":lname, "pfname":pfname, "liprofile":liprofile, 'password':password}
- # profile_id = profiles.insert_one(user).inserted_id
- # contact = {"email": email, "emails": []}
- # contacts.insert_one(contact)
- # sharedd = {"email": email, "emails": []}
- # shared.insert_one(sharedd)
- # requestedd = {"email": email, "emails": []}
- # requested.insert_one(requestedd)
- #}
- if _name_ == "_main_":
- app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement