Exemple #1
0
def review(token,company):
    user = User.api_authenticate(token)
    if user:
        data = request.get_json()
        new_review = Review(None,data['review'],company,data['time_stamp'],data['pros'],data['cons'],user.pk)
        new_review.save()
        return jsonify({"token":user.api_key})
    return jsonify({"token":""})
Exemple #2
0
def addReview(api_key,name,city):
    example = User.api_authenticate(api_key)
    example_two = Food.food_authenticate(name,city)
    if example:
            data=request.get_json()
            new_review =Review(0,name,data['Rating'],example.email,city,example.First_name,example.Last_name,example.image_path)
            new_review.save()
            if new_review:
              return jsonify({"token":example.Api_key})
    return jsonify({"token":""})
Exemple #3
0
def happy(token,company):
    user = User.api_authenticate(token)
    if user:
        output = user.get_company(company)
        happy = Job.job_happiness(company)
        reviews = Review.count_reviews(company)
        return jsonify({"output":output,"happy":happy,"reviews":reviews})
    return jsonify({"error":"failed"})
Exemple #4
0
def company(token,company):
    user = User.api_authenticate(token)
    if user:
        output = user.get_company(company)
        average = user.get_avg_sal(company)
        max_sal = user.get_highest_pos(company)
        data = user.get_search_data(company)
        review = Review.count_reviews(company)
        return jsonify({"output":output,"avg":average,"max":max_sal,"data":data,"review":review})
    return jsonify({"error":"failed"})
Exemple #5
0
def contact():

    contactform = ContactForm()
    applicationform = ApplicationForm()
    reviewform = ReviewForm()

    if contactform.validate_on_submit():
        newcontact = Contact(name=contactform.name.data,
                             email=contactform.email.data,
                             subject=contactform.subject.data,
                             message=contactform.message.data)
        db.session.add(newcontact)
        try:
            db.session.commit()
        except:
            db.session.rollback()

    if applicationform.validate_on_submit():
        newapp = Application(name=applicationform.name.data,
                             number=applicationform.number.data,
                             description=applicationform.description.data)
        db.session.add(newapp)
        try:
            db.session.commit()
        except:
            db.session.rollback()

    if reviewform.validate_on_submit():
        newreview = Review(name=reviewform.name.data,
                           review=reviewform.review.data)
        db.session.add(newreview)
        try:
            db.session.commit()
        except:
            db.session.rollback()

    return render_template(
        "contact.html",
        contactform=contactform,
        applicationform=applicationform,
        reviewform=reviewform,
    )
Exemple #6
0
def csv_to_db(file_path):
    """Write csv to db"""
    with open(file_path, mode='r', newline="", encoding="utf-8") as f:
        reader = csv.DictReader(f)
        for row in reader:
            if os.path.basename(file_path) == "products.csv":
                product = Product(
                    title=row['Title'],
                    asin=row['Asin']
                )
                db.session.add(product)
                db.session.commit()
            elif os.path.basename(file_path) == "reviews.csv":
                review = Review(
                    title=row['Title'],
                    review=row['Review'],
                    product_asin=row['Asin']
                )
                db.session.add(review)
                db.session.commit()
Exemple #7
0
          author_surname='Diamond',
          month='August',
          year='2019')
db.session.add(b1)
db.session.add(b2)
db.session.add(b3)
db.session.add(b4)
db.session.add(b5)
try:
    db.session.commit()
except Exception:
    db.session.rollback()

rev1 = Review(id=111,
              text='This book is amazing...',
              stars=5,
              reviewer_id=r1.id,
              book_id=b1.id)
rev2 = Review(id=112,
              text='The story is hard to follow.',
              stars=3,
              reviewer_id=r2.id,
              book_id=b1.id)
rev3 = Review(id=113,
              text='The story is quite complicated.',
              stars=2,
              reviewer_id=r1.id,
              book_id=b2.id)
rev4 = Review(
    id=114,
    text=
Exemple #8
0
def get_data(places, c):
    for place in places:
        nlow = place.name.lower()
        lterms = [
            'inss', u'previdência social', u'instituto nacional seguro social',
            u'instituto nacional do seguro social', u'previdencia social',
            u'instituto nacional seguro social.'
        ]
        found = False
        for text in lterms:
            if text in nlow:
                found = True

        if not found:
            print("descartou {0}".format(nlow))
            continue

        p = db.session.query(Place).filter_by(id=place.place_id).first()
        if not p:
            place.get_details()
            # city = place.details['address_components'][2]['short_name']
            # state = place.details['address_components'][3]['short_name']
            city, state = get_city_state(place.details['address_components'])
            p = Place(id=place.place_id,
                      address=place.formatted_address,
                      lat=place.geo_location['lat'],
                      lng=place.geo_location['lng'],
                      name=place.name,
                      local_phone_number=place.local_phone_number,
                      rating=place.rating,
                      city=city,
                      state=state,
                      endereco=c[7],
                      bairro=c[0],
                      municipio=c[9],
                      cep=c[1],
                      cnpj=c[2],
                      cod_unid_gestora=c[3],
                      cod_uo_inss=c[4],
                      gex=c[8],
                      sigla_uo_inss=c[10],
                      telefone='{0}{1}'.format(c[6], c[11]),
                      tipo=c[12],
                      status_ativo=c[14])

            db.session.add(p)

            try:
                db.session.commit()
            except:
                db.session.rollback()
                pass

            print(u'added place: {0}'.format(place.formatted_address))

            if 'reviews' in place.details:
                for i in place.details['reviews']:
                    dt_object = datetime.datetime.fromtimestamp(i['time'])
                    rev = Review(
                        author_name=i['author_name'],
                        author_url=i['author_url'],  # language=i['language'],
                        profile_photo_url=i['profile_photo_url'],
                        rating=i['rating'],
                        relative_time_description=i[
                            'relative_time_description'],
                        text=i['text'],
                        time=i['time'],
                        date=dt_object.date())

                    p.reviews.append(rev)
                    try:
                        db.session.commit()
                    except:
                        db.session.rollback()
                        pass

                    print(u'added review: {0}'.format(i['text']))
        else:
            print(u'updated place: {0}'.format(c[9]))
            p.bairro = c[0]
            p.municipio = c[9]
            p.cep = c[1]
            p.cnpj = c[2]
            p.cod_unid_gestora = c[3]
            p.cod_uo_inss = c[4]
            p.gex = c[8]
            p.sigla_uo_inss = c[10]
            p.telefone = '{0}{1}'.format(c[6], c[11])
            p.tipo = c[12]
            p.status_ativo = c[14]
            p.endereco = c[7]

            db.session.add(p)
            try:
                db.session.commit()
            except:
                db.session.rollback()
                pass
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()
# genres = session.query(Genre).all()
books = session.query(Book).all()

from app import app, db, Review

for book in books:
    asin = re.search(r"[\dA-Z]{10}", book.link.href).group()
    post_author = book.link.post.author
    post_url = book.link.post.url
    new_review = Review(item_title=book.title[:249], 
            item_author=book.author, 
            item_image_url=book.image_url, 
            item_asin=asin, 
            author=post_author,
            post_url=post_url,
            date=book.link.post.date)
    new_review.genres = ' '.join([genre.name for genre in book.genres])
    # for genre in book.genres:
        # if genre.name:
            # new_review.genres += genre.name + ' '
    db.session.add(new_review)

db.session.commit()
# dg = db.session.query(DeployedGenre).all()
# for g in dg:
#     print g.name

Exemple #10
0
 def test_review_to_dict_method(self):
     labrynthes = self.review_fixtures['labrynthes']
     review = Review(**labrynthes)
     self.assertEqual(labrynthes['item_author'], review.to_dict()['item_author'])
     self.assertEqual(labrynthes['item_title'], review.to_dict()['item_title'])
Exemple #11
0
b1 = Book(id=123,
          title='Demian',
          author_name="Hermann",
          author_surname='Hesse',
          month="February",
          year=2020)
r1 = Reader(id=342, name='Ann', surname='Adams', email='*****@*****.**')

print("My first reader:", r1.name)

#Checkpoint 1:
b2 = Book(id=533,
          title='The Stranger',
          author_name='Albert',
          author_surname='Camus',
          month='April',
          year=2019)
#Checkpoint 2:
r2 = Reader(id=765, name='Sam', surname='Adams', email='*****@*****.**')
#Checkpoint 3:
print(b2.author_surname)
#Checkpoint 4:
print(len(r2.email))
# Review entry
rev2 = Review(id=450,
              text="This book is difficult!",
              stars=2,
              reviewer_id=r2.id,
              book_id=b2.id)
print(len(rev2.text.split()))
Exemple #12
0
def getReview (token):
    token = User.api_authenticate(token)
    email = Review.all_for_account(token.email)
    if email:
        return jsonify({"reviews":email})
    return jsonify({"token":""})            
Exemple #13
0
def searchuserss(Email):
        data=request.get_json()
        review = Review.ones_from_account(Email)
        if review:
            return jsonify({"reviews":review})
        return jsonify({"message":"failed"})
Exemple #14
0
def company_review(company,token):
    user = User.api_authenticate(token)
    if user:
        reviews = Review.get_reviews(company)
        return jsonify({"reviews":reviews})
    return jsonify({"error":"failed"})
Exemple #15
0
r1 = Reader(id=342, name='Ann', surname='Adams', email='*****@*****.**')

b2 = Book(id=533,
          title='The Stranger',
          author_name='Albert',
          author_surname='Camus',
          month="April",
          year=2019)
r2 = Reader(id=765, name='Sam', surname='Adams', email='*****@*****.**')

print("My first reader:", r1.name)
print("My first author:", b2.author_surname)
print(len(r2.email))

# Creating database entries: relationships
rev1 = Review(id=435,
              text='This book is amazing...',
              stars=5,
              reviewer_id=r1.id,
              book_id=b1.id)
print(rev1)  #prints the rev1 object
print(rev1.text)  #prints the text of the review rev1
print(
    rev1.book_id)  #prints the id of the book for which the review was written

#Checkpoint 1:
rev2 = Review(id=450,
              text="This book is difficult!",
              stars=2,
              reviewer_id=r2.id,
              book_id=b2.id)