예제 #1
0
파일: app.py 프로젝트: minaguirguis/JobFind
def add_Applied():
    """this function is called in jobs.js and adds an APPLIED job to jobs tables"""
    temp_list = []
    data = request.get_json()
    #data = request.args['favorite'].split(',')
    appl_job_title = data['title']
    appl_job_location = data['location']
    appl_job_salary = data['salary']
    appl_job_id = str(data['id'])
    appl_job_link = str(data['link'])

    #all_fav = models.Person.query.filter_by(id=user_id).first()
    all_applied = db.session.query(  # pylint: disable=E1101 
        models.Person).filter_by(id=records[0]).first()

    if all_applied is None:
        print("Record is not founded")
        new_entry = models.Person(id=records[0],
                                  email=records[1],
                                  favorites=[],
                                  applied=[appl_job_id])
        db.session.add(new_entry)
        db.session.commit()
    else:
        if appl_job_id not in all_applied.applied:
            temp_list = all_applied.applied
            client_id = all_applied.id
            temp_email = all_applied.email
            temp_fav = all_applied.favorites
            db.session.delete(all_applied)
            db.session.commit()

            temp_list.append(str(appl_job_id))

            #if all_fav.favorites is None:
            new_entry = models.Person(id=client_id,
                                      email=temp_email,
                                      favorites=temp_fav,
                                      applied=temp_list)
            db.session.add(new_entry)
            db.session.commit()
        else:
            print("ID is already in applied list")

    applied = db.session.query(  # pylint: disable=E1101 
        models.Jobs).filter_by(job_id=appl_job_id).first()

    if applied is None:
        print("Job is not founded")
        new_entry = models.Jobs(job_id=appl_job_id,
                                job_title=appl_job_title,
                                job_location=appl_job_location,
                                job_salary=appl_job_salary,
                                job_link=appl_job_link)
        db.session.add(new_entry)
        db.session.commit()
    else:
        print("Job is already in the database")

    return "Something went wrong"
예제 #2
0
def add_user(
        data):  # data is whatever arg you pass in your emit call on client
    '''add new user to db'''

    users = get_all_users()
    if len(data['dic']) > 1:
        new_date = date.today()
        new_user = models.Person(username=data['dic']['X'],
                                 score=100,
                                 date=new_date)
        if data['dic']['X'] not in users:
            DB.session.add(new_user)
            DB.session.commit()
            users.append(new_user.username)

        new_user2 = models.Person(username=data['dic']['O'],
                                  score=100,
                                  date=new_date)
        if data['dic']['O'] not in users:

            DB.session.add(new_user2)
            DB.session.commit()
            users.append(new_user2.username)
    SOCKETIO.emit('dicrecieved', data, broadcast=True, include_self=False)
    return users
예제 #3
0
def add_favourites():
    """this function is called in jobs.js and adds a FAVORITED job to jobs tables"""
    temp_list = []
    data = request.get_json()
    #data = request.args['favorite'].split(',')
    print("Returned dictionay from jobs.js")
    print()
    print(data)
    uni_id = data['user_id']
    fav_job_title = data['title']
    fav_job_location = data['location']
    fav_job_salary = data['salary']
    fav_job_id = str(data['id'])
    fav_job_link = data['link']

    #all_fav = models.Person.query.filter_by(id=user_id).first()
    all_fav = db.session.query(  # pylint: disable=E1101 
        models.Person).filter_by(id= uni_id ).first()
    
    if all_fav is None:
        print("Record is not founded")
        new_entry = models.Person(id=uni_id, email=global_email, favorites=[fav_job_id], applied=[])    
        db.session.add(new_entry)
        db.session.commit()
    else:
        if fav_job_id not in all_fav.favorites:
            temp_list = all_fav.favorites
            client_id = all_fav.id
            temp_email = all_fav.email
            temp_applied = all_fav.applied
            db.session.delete(all_fav)
            db.session.commit()
            
            temp_list.append(str(fav_job_id))
            
            
            #if all_fav.favorites is None:
            new_entry = models.Person(id=client_id, email=temp_email,favorites=temp_list,applied=temp_applied)    
            db.session.add(new_entry)
            db.session.commit()
        else:
            print("ID is already favorited")
        
        
    favorited = db.session.query(  # pylint: disable=E1101 
        models.Jobs).filter_by(job_id= fav_job_id ).first()
    
    if favorited is None:
        print("Job is not founded")
        new_entry = models.Jobs(job_id=str(fav_job_id), job_title=fav_job_title, job_location=fav_job_location, job_salary=fav_job_salary, job_link=fav_job_link)    
        db.session.add(new_entry)
        db.session.commit()
    else:
        print("Job is already in the database")
    
    
    return "Something went wrong"
예제 #4
0
def person(request):
    dict = None
    if request.method == 'GET':
        dict = request.GET
    elif request.method == 'POST':
        dict = request.POST
    name = dict['Name']
    lname = dict['lName']
    if len(name) == 0 or len(lname) == 0:
        h = HttpResponse()
        h.write('Name or/and Last Name is/are incorrect<br>')
        return h
    p = models.Person(first_name=name, last_name=lname)
    try:
        p.save()
        h = HttpResponse(
            'Data stored<br> <INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);"><br>'
        )
        h.write(
            '<html><head><META HTTP-EQUIV="REFRESH" CONTENT="1;URL=/Form/"></head></html>'
        )
        return h

    except IOError:
        return HttpResponse('Temp2.html error')
def addNewPlayerToDB(currentUser):
    temp = models.Person.query.filter_by(username=currentUser).first()
    if not temp:
        #working with databsse
        new_user = models.Person(username=currentUser, score=100)
        db.session.add(new_user)
        db.session.commit()
예제 #6
0
def import_data(filename):
    """Import data from csv file."""
    with Path(filename).open() as csv_file:
        csv_reader = csv.reader(csv_file, delimiter=',')
        next(csv_reader)  # skip header
        buffer, count = [], 0
        for row in csv_reader:
            count += 1
            survived, pclass, name, sex, age, siblings, parents, fare = row
            buffer.append(
                models.Person(survived=bool(survived),
                              passenger_class=int(pclass),
                              name=name,
                              sex=sex,
                              age=int(float(age)),
                              siblings_or_spouses_aboard=int(float(siblings)),
                              parents_or_children_aboard=int(parents),
                              fare=float(fare)))
            if len(buffer) % 10000 == 0:
                print(f'Imported: {count} items')
                db.session.bulk_save_objects(buffer)
                db.session.commit()
                buffer = []
        if buffer:
            print(f'Imported: {count} items')
            db.session.bulk_save_objects(buffer)
            db.session.commit()
예제 #7
0
def create_person_stocks_db(db: Session, person: schemas.PersonCreate):
    stock_list = person.stocks
    print("stock_list : ", stock_list)
    print("type(stock_list) : ", type(stock_list))
    db_person = models.Person(name=person.name,
                              email=person.email,
                              created_on=datetime.now(),
                              updated_by=person.updated_by)
    db.add(db_person)
    db.commit()
    db.refresh(db_person)
    print("db_person : ", db_person)
    for stock in stock_list:
        print("stock : ", stock)
        print("type(stock) : ", type(stock))
        print("db_person.id : ", db_person.id)
        db_stock = models.Stock(stock_name=stock.stock_name,
                                buy_price=stock.buy_price,
                                sell_price=stock.sell_price,
                                charges=stock.charges,
                                created_on=datetime.now(),
                                updated_by=stock.updated_by,
                                person_id=db_person.id)
        print("db_stock : ", db_stock)
        print("type(db_stock) : ", type(db_stock))
        db.add(db_stock)
        db.commit()
        db.refresh(db_stock)
        print("db_person : ", db_person)
    return {"status": "success"}
예제 #8
0
def add_favourites():
    temp_list = []
    data = request.args['favorite'].split(',')
    #print(data[4])
    fav_job_id = data[4]
    #print(all_entry)
    
    
    #all_fav = models.Person.query.filter_by(id=user_id).first()
    all_fav = db.session.query(  # pylint: disable=E1101 
        models.Person).filter_by(id=user_id ).first()
    #print(all_fav.favorites)
    temp_list = all_fav.favorites
    client_id = all_fav.id
    temp_email = all_fav.email
    temp_applied = all_fav.applied
    db.session.delete(all_fav)
    db.session.commit()
    
    temp_list.append(str(fav_job_id))
    print(temp_list)
    print(client_id)
    print(temp_email)
    print(temp_applied)
    
    #if all_fav.favorites is None:
    new_entry = models.Person(id=client_id, email=temp_email,favorites=temp_list,applied=temp_applied)    
    db.session.add(new_entry)
    db.session.commit()
        
    #print(all_fav.favorites)
    
    
    return "Something went wrong"
예제 #9
0
파일: person.py 프로젝트: matt598/GHVII
def add():
    if request.method == 'GET':
        return render_template(
            'person_add.html',
            countries=data.get_countries(),
            languages=models.Language.query.all(),
        )

    first_name = request.form.get('first-name')
    last_name = request.form.get('last-name')
    email = request.form.get('email')
    phone = request.form.get('phone')
    country = request.form.get('country')
    language = request.form.get('language')

    person = models.Person()
    person.first_name = first_name
    person.last_name = last_name
    person.email = email
    person.phone = phone
    person.origin_country = country

    language = models.Language.query.get(language)
    print(language)
    person.languages.append(language)

    db.session.add(person)
    db.session.commit()

    return redirect(url_for('.view', person_id=person.id))
예제 #10
0
    def get_data(self, param):
        '''
        "AttributeType": "S | N | B"
        '''
        filter_expression = []
        expression_attribute_names = {}
        expression_attribute_values = {}

        net_worth = param.get('net_worth', None)
        if bool(net_worth):
            filter_expression.append('(#net_worth <= :net_worth)')
            expression_attribute_names['#net_worth'] = 'net_worth'
            expression_attribute_values[':net_worth'] = int(net_worth)

        city = param.get('city', None)
        if bool(city):
            filter_expression.append('(#city = :city)')
            expression_attribute_names['#city'] = 'city'
            expression_attribute_values[':city'] = city

        context = models.Person().scan(filter_expression,
                                       expression_attribute_names,
                                       expression_attribute_values)

        return context
예제 #11
0
def parse_people(collect_ids_pass=False):
    check_preconditions(collect_ids_pass)
    f = open(JSON_DUMP_DIR + PEOPLE_FILENAME, "r")
    people_json = json.loads(f.read())
    people_list = []
    for people_dict in people_json:
        person_id = people_dict['id']
        if collect_ids_pass:
            _KNOWN_PEOPLE.add(person_id)
        else:
            city = people_dict['city']
            name = people_dict['name']
            twitter = people_dict['twitter']
            summary = people_dict['summary']
            logo_url = people_dict['logo_url']
            companies_and_roles = people_dict['companies']
            if city not in _KNOWN_CITIES:
                city = None
            roles = []
            companies = []
            for c in companies_and_roles:
                roles += [c['role']]
                companies += [[c['name'], c['id']]]
            companies = filter_contains(_KNOWN_COMPANIES, companies)
            p = models.Person(person_id, name, summary, city, json.dumps(companies), json.dumps(roles), twitter,
                              logo_url)
            people_list += [p]
    return people_list
예제 #12
0
    def setUp(self):

        self.success_test_params = [
            {
                KEY_INPUT: 'Amy',
                KEY_EXPECTED: [INITIAL_USERNAME, 'Amy'],
            },
            {
                KEY_INPUT: 'Bob',
                KEY_EXPECTED: [INITIAL_USERNAME, 'Amy', 'Bob'],
            },
            {
                KEY_INPUT: 'Charlie',
                KEY_EXPECTED: [INITIAL_USERNAME, 'Amy', 'Bob', 'Charlie'],
            },
        ]
        self.failure_test_params = [
            {
                KEY_INPUT: 'Amy',
                KEY_EXPECTED: [INITIAL_USERNAME],
            },
            {
                KEY_INPUT: 'Bob',
                KEY_EXPECTED: [INITIAL_USERNAME, 'Bob'],
            },
            {
                KEY_INPUT: 'Charlie',
                KEY_EXPECTED: ['Charlie'],
            },
        ]
        initial_person = models.Person(username=INITIAL_USERNAME,
                                       recs="Greys Anatomy")
        self.initial_db_mock = [initial_person]
예제 #13
0
def delete(request, ident):
    p = models.Person(id=ident)
    p.delete()
    h = HttpResponse()
    h.write(
        '<html><head><META HTTP-EQUIV="REFRESH" CONTENT="0.01;URL=/Form/"></head></html>'
    )
    return h
예제 #14
0
 def add(self):
     person = models.Person()
     person.name = input('Name: ')
     person.gender = input('Gender: ')
     person.salary = float(input('Salary: '))
     person.date_birth = helpers.transform_date(
         input('Date birth (YYYY-MM-DD): '))
     self.database.save(str(person))
예제 #15
0
def add_new_player(current_user):
    ''' helper method to add new player to database '''
    temp = models.Person.query.filter_by(username=current_user).first()
    if not temp:
        #working with databsse
        new_user = models.Person(username=current_user, score=100)
        db.session.add(new_user)
        db.session.commit()
예제 #16
0
def logged(data):
    """add user to database"""
    print(data)
    print(data)
    people = models.Person(username=data, password='******')
    #db.session.add(people)
    #db.session.commit()
    if (addUser(data, 'default')):
        print('success!')
    def setUp(self):
        self.success_test_params = [
            {
                KEY_INPUT: 'user2',
                KEY_EXPECTED: [INITIAL_USERNAME, 'user2'],
            },
        ]

        initial_person = models.Person(username=INITIAL_USERNAME, score=100)
        self.initial_db_mock = [initial_person]
예제 #18
0
def add_user(current_user):
    ''' helper method to add new player to database '''
    new_user = models.Person(username=current_user, score=100)
    db.session.add(new_user)
    db.session.commit()
    players = []
    all_people = models.Person.query.all()
    for person in all_people:
        players.append(person.username)
    return players
예제 #19
0
def zhu_ce():
    print("根据提示注册")

    # 提示用户输入用户名
    new_user = input("请输入用户名:")
    age = input("请输入年龄:")
    gender = input("请输入性别:")
    p1 = models.Person(new_user, age, gender)
    p[new_user] = p1
    show_long()
예제 #20
0
파일: main.py 프로젝트: page31/intranet
    def get(self):
        """When the user grants access, they are redirected back to this
      handler where their authorized request token is exchanged for a
      long-lived access token."""

        client = gdata.apps.client.AppsClient(domain="wandoujia.com")
        client.ssl = True

        current_user = users.get_current_user()

        # Remember the token that we stashed? Let's get it back from
        # datastore now and adds information to allow it to become an
        # access token.
        request_token_key = 'request_token_%s' % current_user.email()
        request_token = gdata.gauth.ae_load(request_token_key)
        gdata.gauth.authorize_request_token(request_token, self.request.uri)

        # We can now upgrade our authorized token to a long-lived
        # access token by associating it with gdocs client, and
        # calling the get_access_token method.
        client.auth_token = client.get_access_token(request_token)

        # Note that we want to keep the access token around, as it
        # will be valid for all API calls in the future until a user
        # revokes our access. For example, it could be populated later
        # from reading from the datastore or some other persistence
        # mechanism.
        access_token_key = 'access_token_%s' % current_user.email()
        gdata.gauth.ae_save(request_token, access_token_key)

        # Write user info into database

        user_name = current_user.email().split('@')[0]
        logging.info(user_name)
        person = models.Person().get_by_key_name(user_name)
        if not person:
            person = models.Person(gaia=current_user,
                                   email=current_user.email(),
                                   key_name=user_name)
        person.is_setup = True
        person.put()
        memcache.flush_all()
        self.redirect('/')
예제 #21
0
def adding_new_user(user_name):
    '''This function is to test the mocked test to add a user'''
    temp_users = []
    new_user = models.Person(username=user_name, score=100)
    DB.session.add(new_user)  # pylint: disable=E1101
    DB.session.commit()  # pylint: disable=E1101
    all_people = models.Person.query.all()
    for person in all_people:
        temp_users.append(person.username)
    return temp_users
예제 #22
0
    def post(self):

        name = self.request.get('name')
        email = self.request.get('email')

        person = models.Person.query(models.Person.email == email).get()

        if not person:
            person = models.Person(name=name, email=email)
            person.put()

        return webapp2.redirect('/person/' + person.key.urlsafe())
예제 #23
0
def angular():

  if request.method == 'POST':
    print("post method")
    username = request.form.get('name')
    email = request.form.get('email')
    password = request.form.get('password')

    person = models.Person(username, email, password)
    db.session.add(person)
    db.session.commit()
    return jsonify({'text': 'Hello World!'})
예제 #24
0
    def setUp(self):
        self.success_test_params = [
            {
                KEY_INPUT: 'naman',
                KEY_EXPECTED: [INITIAL_USERNAME, 'naman'],
            },
        ]

        initial_person = models.Person(
            username=INITIAL_USERNAME,
            email='{0}@stuff.com'.format(INITIAL_USERNAME))
        self.initial_db_mock = [initial_person]
예제 #25
0
def add_user_to_db(username):
    '''
    This method is simply to query the username from the database check if the
    user is in there if its not there add it otherwise don't do anything. While
    youre adding to it, instantiating the scores to 100.
    @param username : the username that the user entered
    '''
    new_user = models.Person.query.filter_by(username=username).first()
    if new_user is None:
        new_user = models.Person(username=username, scores=100)
        db.session.add(new_user)
        db.session.commit()
예제 #26
0
def create_person():
    # get the name first, if no name then fail
    name = request.form.get("name")
    if not name:
        return make_response(jsonify({"code": 403,
                                      "msg": "Cannot put person. Missing mandatory fields."}), 403)
    person_id = request.form.get("id")
    if not person_id:
        p = models.Person(name=name)
    else:
        p = models.Person(id=person_id, name=name)

    models.db.session.add(p)
    try:
        models.db.session.commit()
    except sqlalchemy.exc.SQLAlchemyError as e:
        error = "Cannot put person. "
        print(person_bp.config.get("DEBUG"))
        if person_bp.config.get("DEBUG"):
            error += str(e)
        return make_response(jsonify({"code": 404, "msg": error}), 404)
    return jsonify({"code": 200, "msg": "success"})
예제 #27
0
def get_person(person_url):
    try:
        return DB_MANAGER.open().query(
            mo.Person).filter(mo.Person.api_url == person_url).one()
    except:
        try:
            person_obj = get_request(person_url)
            person = mo.Person()
            person.parse_json(person_obj)
            person = DB_MANAGER.save(person)
            return person
        except:
            return None
예제 #28
0
def create_person():
    data = request.get_json()
    maxID = db.session.query(func.max(
        models.Person.id)).scalar()  #gets current maximum ID in Person table
    new_person = models.Person(id=maxID + 1,
                               name=data['name'],
                               email=data['email'],
                               password=data['person'],
                               phone=data['phone'],
                               admin=False)
    db.session.add(new_person)
    db.session.commit()
    return jsonify({'message': 'New user created!'})
예제 #29
0
def add_user_to_db_mock(username):
    '''
    This method is simply to mock the db
    @param username : the username that the user entered
    '''
    new_user = models.Person(username=username, scores=100)
    db.session.add(new_user)
    db.session.commit()
    database_players = models.Person.query.all()
    players = []
    for user in database_players:
        players.append(user.username)
    return players
예제 #30
0
    def create(self, request):
        data = json.loads(request.body)
        if type(data) != list:
            data = [data]

        for d in data:
            person = models.Person(name=d.get('name', ''),
                                   age=d.get('age', ''),
                                   sex=d.get('sex', ''),
                                   comment=d.get('comment', ''))
            person.save()

        return Response({'status': 'OK'})