Example #1
0
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from database_setup import Base, User, Categories, Item

engine = create_engine("sqlite:///catalog.db")
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
session = DBSession()

user1 = User(name="Tom", email="*****@*****.**")
session.add(user1)
session.commit()

catalog1 = Categories(name="Macbook")
session.add(catalog1)
session.commit()

catalog2 = Categories(name="Macbook Air")
session.add(catalog2)
session.commit()

catalog3 = Categories(name="Macbook Pro")
session.add(catalog3)
session.commit()

catalog3 = Categories(name="iMac")
session.add(catalog3)
session.commit()
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from database_setup import Category, Base, Item, User

engine = create_engine('sqlite:///items.db')

Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)

session = DBSession()

defaultuser = User(name="test", email="*****@*****.**")
defaultuser.hash_pw("test")
session.add(defaultuser)
session.commit()

category1 = Category(name="Bikes", user=defaultuser)
session.add(category1)
session.commit()

category2 = Category(name="Sports", user=defaultuser)
session.add(category2)
session.commit()

item1 = Item(title="Football", description="nice game",
             imgSource="http://placekitten.com/g/200/300", category=category2,
             user=defaultuser)
session.add(item1)
session.commit()
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# Create dummy user
User1 = User(
    name="Robo Barista",
    email="*****@*****.**",
    picture=
    'https://pbs.twimg.com/profile_images/2671170543/18debd694829ed78203a5a36dd364160_400x400.png'
)
session.add(User1)
session.commit()

# Menu for UrbanBurger
restaurant1 = Restaurant(user_id=1, name="Urban Burger")

session.add(restaurant1)
session.commit()

menuItem2 = MenuItem(
    user_id=1,
    name="Veggie Burger",
    description="Juicy grilled veggie patty with tomato mayo and lettuce",
Example #4
0
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()


#create users
User1 = User(name="Udacity", email="*****@*****.**",
             picture='https://pbs.twimg.com/profile_images/2671170543/18debd694829ed78203a5a36dd364160_400x400.png')
session.add(User1)
session.commit()


# Item for snowboarding
category1 = Category(user_id=1, name="Snowboarding")

session.add(category1)
session.commit()


item1 = Item(name="Snowboard", description="Best for any terrain and conditions. All-mountain snowboards perform anywhere on a mountain-groo,ed runs, backcountry, even park and pipe.",
                     category = category1, user=User1)

session.add(item1)
Example #5
0
def createUser(login_session):
    newUser = User(name=login_session['username'], email=login_session['email'], picture=login_session['picture'])
    session.add(newUser)
    session.commit()
    user = session.query(User).filter_by(email=login_session['email']).one()
    return user.id
Example #6
0
import json
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from database_setup import Base, User, Category, Item

engine = create_engine('sqlite:///catalog.db')
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
session = DBSession()

user = User(name='Azalea', email='*****@*****.**',
            picture='https://octodex.github.com/images/welcometocat.png')
session.add(user)
session.commit()

categories = [
    Category(name='Book', glyphicon='glyphicon-book'),
    Category(name='Movie', glyphicon='glyphicon-film'),
    Category(name='TV series', glyphicon='glyphicon-hd-video'),
    Category(name='Album', glyphicon='glyphicon-music'),
]
session.bulk_save_objects(categories)

items = []
# populate items through json data in 'catalog.json'
json_data = json.loads(open('catalog.json').read())
category_data = json_data['Category']
for category in category_data:
    items.extend([Item(**item_data) for item_data in category['items']])
Example #7
0
from sqlalchemy.orm import sessionmaker

from database_setup import Restaurant, Base, MenuItem, User

# engine = create_engine('sqlite:///restaurantmenuwithusers.db')
engine = create_engine('postgresql://*****:*****@localhost/catalog')

Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)

session = DBSession()


# Create dummy user
User1 = User(name="Apurva Gaikwad", email="*****@*****.**",
             picture='https://lh3.googleusercontent.com/-U4dMY7_bhDc/XUb-oa5f2RI/AAAAAAAAAaw/_KdCT89Ca002o9hEUKw4FzqMnp3eLbjAQCEwYBhgL/w139-h140-p/IMG_20190406_144254.jpg')
session.add(User1)
session.commit()


# Menu for Aish, Hyderabad
restaurant1 = Restaurant(user_id=1, name="AISH, HYDERABAD")

session.add(restaurant1)
session.commit()

menuItem1 = MenuItem(user_id=1, name="Kodi, miriyalu rasam", description="The definitive chicken and black pepper broth",
                     price="Rs. 425", course="Soups", restaurant=restaurant1)

session.add(menuItem1)
session.commit()
Example #8
0
engine = create_engine('postgresql://*****:*****@localhost/vgcatalog')
# Bind the engine to the metadata of the Base class so that the
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()
# Add my info
User1 = User(name="Ryan Fernandez", email="*****@*****.**")
session.add(User1)
session.commit()

# Menu for SNES
category1 = Category(user_id=1, name="SNES")

session.add(category1)
session.commit()

item1 = Item(user_id=1,
             name="Base Console",
             description="SNES Console with one controller",
             category=category1)

session.add(item1)
Example #9
0
# Bind the engine to the metadata of the Base class so that the
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# Create a user
nimit = User(name="Nimit Bhargava", email="*****@*****.**")
session.add(nimit)
session.commit()

rajasthan = Category(name="Rajasthan", owner_id=1)
session.add(rajasthan)
session.commit()

# Items for Rajasthan
ajmer = Item(
    title="Ajmer",
    owner_id=1,
    description=
    "Ajmer is a city in the northern Indian state of Rajasthan. South of the city's artificial Ana Sagar Lake is Ajmer Sharif Dargah, the domed shrine of the Muslim Sufi saint Garib Nawaz.",
    category=rajasthan)
session.add(ajmer)
Example #10
0
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# create a dummy user
user1 = User(name="Akshay Menon",
             email="*****@*****.**",
             picture='http://lorempixel.com/200/200/people/1')
session.add(user1)
session.commit()

user2 = User(name="Sharath Kumar",
             email="*****@*****.**",
             picture='http://lorempixel.com/200/200/people/2')
session.add(user2)
session.commit()

user3 = User(name="Mithun Airani",
             email="*****@*****.**",
             picture='http://lorempixel.com/200/200/people/3')
session.add(user3)
session.commit()
Example #11
0
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# Create dummy user
user1 = User(
    name='Yummy Desserts',
    email='*****@*****.**',
    picture=
    'https://pbs.twimg.com/profile_images/2671170543/18debd694829ed78203a5a36dd364160_400x400.png'
)

session.add(user1)
session.commit()

category1 = Category(user_id=1, name='Cakes')

session.add(category1)
session.commit()

item1 = Item(
    user_id=1,
    name='Red Velvet Cake',
    description=
Example #12
0
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from database_setup import User, CatalogItem, Items, Base

engine = create_engine('sqlite:///catalogitems.db')

Base.metadata.bind = engine

DBsession = sessionmaker(bind=engine)

session = DBsession()

User1 = User(name="anjan", email="*****@*****.**")
session.add(User1)
session.commit()

CatalogItem1 = CatalogItem(name="badminton", user_id=1)
session.add(CatalogItem1)
session.commit()

CatalogItem2 = CatalogItem(name="cricket", user_id=1)
session.add(CatalogItem2)
session.commit()

CatalogItem3 = CatalogItem(name="football", user_id=1)
session.add(CatalogItem3)
session.commit()

Item1 = Items(name="shettil",
              description="to play the badminton",
Example #13
0
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

User1 = User(
    name="Marques Butilla",
    email="*****@*****.**",
    picture=
    'https://d2ujflorbtfzji.cloudfront.net/key-image/cca01032-08a1-402e-b0ee-49f6ba9b15d3.png'
)

session.add(User1)
session.commit()

# Menu for UrbanBurger
restaurant1 = Restaurant(user_id=1, name="Urban Burger")

session.add(restaurant1)
session.commit()

menuItem2 = MenuItem(
    user_id=1,
    name="Veggie Burger",
Example #14
0
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

User1 = User(
    name="Aura M",
    email="*****@*****.**",
    picture=
    'https://lh3.googleusercontent.com/a-/AAuE7mDzT5ws-XUJisun8vx5j5HsZqyUlUrzMWSztsyLEA=s192'
)
session.add(User1)
session.commit()

# Menu for UrbanBurger

CatalogItem1 = CatalogItem(
    user_id=1,
    title="Kobo  book service",
    content=
    " If you have a 50+ minute commute each way every day you can use Kobo app . Kobo plans are cheaper than Audible and you can buy additional credits whenever you want (in bulks of 3). We have a big library.",
    catalog_type="Education")

session.add(CatalogItem1)
Example #15
0
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from database_setup import Campground, SiteReview, Base, User

engine = create_engine('sqlite:///campreviewwithusers.db')
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
session = DBSession()

#Create a dummy user 
user1 =User(name="Bob Smith", email="*****@*****.**")

session.add(user1)
session.commit()

#Agate Beach Campground
campground1 = Campground(user_id=1, name ="Agate Beach")

session.add(campground1)
session.commit()

siteReview1 = SiteReview(user_id=1, experience="A beautiful place", description="Located inside the Naikoon National Park. With over 32 tent sites sitting right on the edge of the ocean",
                         category ='Will definitely come back', campground=campground1)
session.add(siteReview1)
session.commit()

siteReview2 = SiteReview(user_id=1, experience ="A great place to unwind", description="Beautiful spacious sites to pitch a tent or park your RV",
                         category="Will definitely come back", campground =campground1)
session.add(siteReview2)
session.commit()
Example #16
0
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# Create dummy user
User1 = User(
    name="John Doe",
    email="*****@*****.**",
    picture=
    'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBwgHBgkIBwgKCgkLDRYPDQwMDRsUFRAWIB0iIiAdHx8kKDQsJCYxJx8fLT0tMTU3Ojo6Iys/RD84QzQ5OjcBCgoKDQwNGg8PGjclHyU3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3N//AABEIAJcAlwMBEQACEQEDEQH/xAAbAAEAAgMBAQAAAAAAAAAAAAAABQYBBAcCA//EAEIQAAEDAwAFBwkECAcAAAAAAAABAgMEBREGEiExURMiQXGBkcEHFjJSVGGTobEVQnPwFCMkNUNy0dIXMzRilOHx/8QAGwEBA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0KnQqcUUgzWaztKgyY7Y7ctoa54wAPpBNLTv16eWSJ6/ejcrVXuPY3jsyraa/yzs3fty7aur9pVWPxFPee3i2eUZfalpTzzVL0fUzSTOTcsj1djvPJmZ7tVpm072nd4PNnhks9BxPJpZ5Z618PD7v8APgyi2zZt9FPcauOlpI1fK9exE6VX3HVxrcFsP20W9H/OjfjrbJblq63ZLVDaLfHSwrnG1713vcu9TmtRntnyTey7xYox1isJA0NoAAAAAAAAAjL5ZaS80/JVLMOanMlbscxfz0GF6RaOrTmwUzV2s5ve9GrhaFc98azU6fx402InvToIl8VqqbNpMmL1bx4oVNqZTca0UAAZAx0Z6AJay6O3C8PbyESxwLvnkTDU6vW7O82Vx2skYdNky9ukeLpdjslJZabkqZuXu/zJXek/88CXSkUjaF1gwUw12qlDNvAAAAAAAAAAABjVAhrjotaLgqvlpUjkXaskK6i/LYvaa7Yq2Rsmkw5Osx8EFU+T6JV/Zri9n4kSO+ioapweEotuGx/bZq/4e1Gf3pF/x1/uPPJ58Wvzbf24+H7tmm8nsSKn6TcZHfhxo36qplGnj1yzrw2P7rfBN2/RKz0Lke2m5aRPvzrrr3bvkbK4qV9SVj0eGnWI+Kba1G4xuTchsSnoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//Z'
)
session.add(User1)
session.commit()

# Soccer category
category1 = Category(user_id=1, name="Soccer")

session.add(category1)
session.commit()

item1 = Item(user_id=1,
             title="Jersey",
             description="Nice Jersey",
             category=category1)
Example #17
0
]

# List of items
ITEMS = [
    Item(category_id=1,
         title="Soccer Cleats",
         description="The shoes",
         user_id=1),
    Item(category_id=1, title="Jersey", description="The shirt", user_id=1),
    Item(category_id=2, title="Jersey", description="The shirt", user_id=1),
    Item(category_id=3, title="Bat", description="The bat", user_id=1),
    Item(category_id=5, title="Snowboard", description="The board", user_id=1)
]

# List of users
USERS = [User(name="John Doe", email="*****@*****.**")]

# Add Categories to DB


def add_categories(categories):
    for category in categories:
        new_category = Category(title=category)
        try:
            session.add(new_category)
            session.commit()
        except exc.IntegrityError:
            session.rollback()


# Add Items to DB
engine = create_engine('postgresql://*****:*****@localhost/emp_catalog')
# Bind the engine to the metadata of the Base class so that the
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

user1 = User(id=2, name='Udacity', email='*****@*****.**')
session.add(user1)
session.commit()

department1 = Department(dept_name='HR', user_id=1)
session.add(department1)
session.commit()

department2 = Department(dept_name='Finance', user_id=1)
session.add(department2)
session.commit()

department3 = Department(dept_name='Sales', user_id=1)
session.add(department3)
session.commit()
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# Create dummy user
user1 = User(name="Peter Simpson",
             email="*****@*****.**",
             picture='https://goo.gl/zxg5oL')
session.add(user1)
session.commit()

# Popular Marvel Universe Characters
category1 = Category(name="Popular Marvel Characters", user_id=1)

session.add(category1)
session.commit()

char1 = CatChar(name="Spiderman",
                user_id=1,
                description="Lorem ipsum dolor sit amet, " +
                "consectetuer adipiscing elit. " +
                "Aenean massa. Cum sociis natoque" + "penatibus et magnis " +
Example #20
0
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from database_setup import Category, Base, User, MenuItem

engine = create_engine('sqlite:///catalog.db')

# Bind engine to metadata of the Base class.
Base.metadata.bind = engine

DBSDession = sessionmaker(bind=engine)
session = DBSDession()

# Create dummy user.
User1 = User(name="Mr Boozehound",
             email="*****@*****.**",
             picture="http:/Bee/static/boozehound.png")
session.add(User1)
session.commit()

# Catgegory for Scotch
category1 = Category(user_id=1,
                     name="Scotch",
                     description="Made in Scotland from barley malt.")

session.add(category1)
session.commit()

menuItem1 = MenuItem(user_id=1,
                     name="Johnny Walker Blue Label",
                     description="The best blended scotch money ($$$) can buy",
Example #21
0
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()


# Create dummy user
User1 = User(username="******", password="******",
             email="*****@*****.**", name="Bill Gates",
             picture="bgates.jpg")

session.add(User1)
session.commit()

User2 = User(username="******", password="******",
             email="*****@*****.**", name="Shantanu Narayen",
             picture="AdobeCEO.jpg")

session.add(User2)
session.commit()

User3 = User(username="******", password="******",
             email="*****@*****.**", name="Adam Selipsky",
             picture="TableauCEO.jpg")
Example #22
0
engine = create_engine('sqlite:///watches.db')
# Bind the engine to the metadata of the Base class so that the
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()
User1 = User(name="vyshnavi", email="*****@*****.**")
session.add(User1)
session.commit()


company1 = Company(user_id=1, name="Titan")
session.add(company1)
session.commit()
article1 = Article(user_id=1, name="Analog", description="ladies watch",
                   price="$60", type="belt", company=company1)

session.add(article1)
session.commit()

article2 = Article(user_id=1, name="Digital", description="boys watches",
                   type="chain", price="$80", company=company1)
Example #23
0
engine = create_engine('sqlite:///catalogitems.db')
# Bind the engine to the metadata of the Base class so that the
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

User1 = User(name="Killumi Zoldick", email="*****@*****.**", picture='')
session.add(User1)
session.commit()

category1 = Categories(id=1, name="Adidas")

session.add(category1)
session.commit()

categoryitem1 = CategoriesItem(id=1,
                               title="NMD",
                               description="NMD",
                               categories_id=1,
                               user_id=1)

session.add(categoryitem1)
Example #24
0
# Bind the engine to the metadata of the Base class so that the
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# creating a  dummy user
User1 = User(name="admin", email="*****@*****.**")
session.add(User1)
session.commit()

# Dummy books data
book1 = BookDB(bookName="The way of the zen",
               authorName="Alan Watts",
               coverUrl="""https://books.google.com/books/content/
               images/frontcover/F9uIBAAAQBAJ?fife=w300-rw""",
               description="bye",
               category="Romance",
               user_id=1)

session.add(book1)
session.commit()
Example #25
0
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# Create dummy users
user_to_add = User(name="Fernando Hippokrates",
                   email="*****@*****.**",
                   picture='https://upload.wikimedia.org/'
                   'wikipedia/commons/0/0d/Kangaroo_and_joey03.jpg')
session.add(user_to_add)
session.commit()

user_to_add = User(name="Rishi Trevelyan",
                   email="*****@*****.**",
                   picture='https://s-media-cache-ak0.pinimg.com/736x/8a/'
                   'b8/53/8ab853a3ce417f5c872e605abdaae6a9--'
                   'panda-bears-god.jpg')
session.add(user_to_add)
session.commit()

user_to_add = User(name="Hubert Marcus",
                   email="*****@*****.**",
                   picture='http://www.kidzone.ws/images-changed/'
Example #26
0
def user(session, name, email, picture_url):
    ''' Creates a new row in the User table '''
    user = User(name=name, email=email, picture=picture_url)
    session.add(user)
    return session.query(User).filter_by(email=email).one()
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# dummy user
User1 = User(
    name="Umair",
    email="*****@*****.**",
    picture=('https://pbs.twimg.com/profile_images/'
             '2671170543/18debd694829ed78203a5a36dd364160_400x400.png'))
session.add(User1)
session.commit()

# Category 1
category1 = Category(name="Philosophy")
session.add(category1)
session.commit()

# Book 1
book1 = Book(name="Politics by Aristotle",
             description="Politics is a work of political philosophy"
             "by Aristotle, a 4th-century BC Greek philosopher.",
             category=category1)
Example #28
0
from database_setup import User, Category, Item

# engine = create_engine('sqlite:///catalog.db')
engine = create_engine('postgresql://*****:*****@localhost/catalog')
Session = sessionmaker(bind=engine)

session = Session()

##########
session.query(Item).delete()
session.query(Category).delete()
session.query(User).delete()
##########

# Create first user.
user = User(username='******', email='*****@*****.**')
session.add(user)
session.commit()

# Item categories
category1 = Category(user_id=1, name="Baseball")

session.add(category1)
session.commit()

Item1 = Item(user_id=1,
             name="Wilson A330 Glove",
             description="Wilson A330 Glove description",
             category=category1)

session.add(Item1)
Example #29
0
def google_connect():
    # validate state token
    if request.args.get('state') != login_session.get('state'):
        response = make_response(json.dumps('Invalid State Parameter!!'), 401)
        response.headers['Content-Type'] = 'application/json'
        return response
    auth_code = request.data

    # Get Access token using auth_code
    try:
        flow = flow_from_clientsecrets('client_secrets.json', scope='')
        flow.redirect_uri = "postmessage"
        credentials = flow.step2_exchange(auth_code)
    except FlowExchangeError:
        response = make_response(json.dumps('Failed to get credentials!!'),
                                 401)
        response.headers['Content-Type'] = 'application/json'
        return response

    # check validity of access token
    access_token = credentials.access_token
    url = ("https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=%s" %
           access_token)
    http = httplib2.Http()
    result = http.request(url, 'GET')[1]
    content = json.loads(result)

    if content.get('error') is not None:
        response = make_response(json.dumps(content.decode().get('error')),
                                 500)
        response.headers['Content-Type'] = 'application/json'
        return response

    # check access token is for intended user or not

    google_plus_id = credentials.id_token['sub']
    if content['user_id'] != google_plus_id:
        response = make_response(
            json.dumps("Token's user ID doesn't match given user ID."), 401)
        response.headers['Content-Type'] = 'application/json'
        return response

    # check access token is intended to this app or not

    if content['issued_to'] != CLIENT_ID:
        response = make_response(
            json.dumps("Token's client ID does not match app's."), 401)
        response.headers['Content-Type'] = 'application/json'
        return response

    stored_access_token = login_session.get('access_token')
    stored_google_plus_id = login_session.get('google_plus_id')
    if stored_access_token is not None and stored_google_plus_id == \
            google_plus_id:
        response = make_response(json.dumps('already connected.'), 200)
        response.headers['Content-Type'] = 'application/json'
        flash("You are already logged in")
        return response
    login_session['access_token'] = access_token
    login_session['google_plus_id'] = google_plus_id

    # access user info
    url = "https://www.googleapis.com/oauth2/v1/userinfo"
    params = {'access_token': access_token, 'alt': 'json'}
    output = requests.get(url, params=params)
    data = output.json()
    login_session['username'] = data['name']
    login_session['email'] = data['email']
    login_session['picture'] = data['picture']
    user = session.query(User).filter(User.email == login_session['email']) \
        .one_or_none()
    if user is None:
        new_user = User(name=login_session['username'],
                        email=login_session['email'],
                        picture=login_session['picture'])
        session.add(new_user)
        session.commit()
        return ''
    else:
        return ''
Example #30
0
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# Create dummy user
User1 = User(
    name="Gerald Goh",
    email="*****@*****.**",
    picture=
    'https://plus.google.com/u/0/photos/103754540034105626879/albums/profile/5731836629516512290'
)
session.add(User1)
session.commit()

# Menu for Crime
genre1 = Genre(user_id=1, title="Crime")

session.add(genre1)
session.commit()

bookItem1 = BookItem(
    user_id=1,
    title="A Dark So Deadly",
    description="No.1 bestselling author of the Logan McRae series.",