def newCity():
    if request.method == 'POST':
        newCity = City(name=request.form['name'],
                       user_id=login_session['user_id'])
        session.add(newCity)
        session.commit()
        flash("City %s is successfully created" % (newCity.name))
        return redirect(url_for('showCity', city_id=newCity.id))
    else:
        return render_template('newCity.html')
Beispiel #2
0
def newCity():
    if 'username' not in login_session:
        return redirect('/login')

    if request.method == 'POST':
        newCity = City(name=request.form['name'],
                       user_id=login_session['user_id'])
        session.add(newCity)
        session.commit()
        return redirect(url_for('showCities'))
    else:
        return render_template('newCity.html')
Beispiel #3
0
def newCity():
    pass
    user_id = getUserID(login_session['email'])
    if not user_id:
        user_id = createUser(login_session)
    login_session['user_id'] = user_id
    if request.method == 'POST':
        newCity = City(name=request.form['name'],
                       user_id=login_session['user_id'])
        session.add(newCity)
        flash("New city created!")
        session.commit()
        return redirect(url_for('city', cities=cities))
    else:
        return render_template('newcity.html')
Beispiel #4
0
def newCity():
    # Only logged in users can add data
    if 'username' not in login_session:
        return redirect('/login')

    if request.method == 'POST':
        newCity = City(
            name=request.form['city'],
            state=request.form['state'],
            user_id=login_session['user_id'])
        session.add(newCity)
        flash('New City "%s" Successfully Created' % newCity.name)
        session.commit()
        return redirect(url_for('showCities'))
    else:
        return render_template('newCity.html')
Beispiel #5
0
def AddNewCity(country_id):
    country = session.query(Country).filter_by(id=country_id).one_or_none()
    creator = getUserInfo(country.user_id)
    if 'username' not in login_session or \
            creator.id != login_session['user_id']:
        return redirect('/login')
    if request.method == 'POST':
        newCity = City(name=request.form['name'],
                       description=request.form['description'],
                       country_id=country_id,
                       user_id=login_session['user_id'])
        session.add(newCity)
        session.commit()
        flash('new city created!')
        return redirect(url_for('SingleCountry', country_id=country_id))
    else:
        return render_template('new-city.html', country_id=country_id)
def newCity():
    """
    Creates city information to the database
    :return:
        on GET: Page to create city
        on Post: Redirect to main page after city has been created
    """
    if 'access_token' not in login_session:
        return redirect(url_for('showLogin'))
    user = session.query(User).filter_by(email=login_session['email']).one()
    if request.method == 'POST':

        newCity = City(name=request.form['name'],
                       description=request.form['description'],
                       user=user)
        session.add(newCity)
        session.commit()
        return redirect(url_for('showCities'))
    else:
        return render_template('newCity.html')
Beispiel #7
0
def main():
    engine = create_engine('sqlite:///cities.db')
    session = Session(bind=engine)
    with open('CitySet_python.csv', 'rb') as f:
        reader = csv.reader(f)
        firstline = True
        for line in reader:
            if firstline:
                firstline = False
                # Enter stat indicators
                #### ADD STAT INDICATORS HERE #####
                cinemastat = StatIndicator(name="Cinema Screens")
                educatedpct = StatIndicator(name="Portion Educated")
                session.add_all([cinemastat, educatedpct])
                session.commit()
                continue
            # Read lines now
            # Create a city object, stat indicator, and flat stat
            city = City(name=line[0],
                        long=parse_float(line[-3]),
                        lat=parse_float(line[-4]),
                        area=parse_float(line[9]))
            citystat = CityStat(city=city,
                                population=parse_float(line[-5]),
                                population_updated=datetime.date.today())
            session.add(city)
            session.add(citystat)
            session.commit()
            session.add(citystat)
            session.commit()
            #### ADD FLAT STATS HERE OF WHICH COLUMN HERE ###
            flatstat1 = FlatStat(stat_id=cinemastat.id,
                                 city_id=city.id,
                                 value=parse_float(line[3]))
            flatstat2 = FlatStat(stat_id=educatedpct.id,
                                 city_id=city.id,
                                 value=parse_float(line[6]))
            session.add(flatstat1)
            session.add(flatstat2)
            session.commit()
Beispiel #8
0
# 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="Robo Barista", email="*****@*****.**",
             picture='https://pbs.twimg.com/profile_images/2671170543/18debd694829ed78203a5a36dd364160_400x400.png')
session.add(User1)
session.commit()

# Menu for UrbanBurger
city1 = City(user_id=1, name="Sacramento")

session.add(city1)
session.commit()

forSale2 = forSale(user_id=1, name="Famfit Shirt", description="large black made out of cotton",
                     price="$19.50", contact="916-233-6433", category="Fashion", city=city1)

session.add(forSale2)
session.commit()


forSale1 = forSale(user_id=1, name="Solar Power Bank", description="Solar Powered battery bank",
                     price="$10.99", contact="916-233-6433", category="Electronics", city=city1)

session.add(forSale1)
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)

session = DBSession()

# create dummy users

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

# city 1 and its attractions

city1 = City(user_id=1, name="New York City")

session.add(city1)
session.commit()

description1 = """The Statue of Liberty Enlightening
    the World was a gift of friendship from the people of France
    to the people of the United States and is a universal
    symbol of freedom and democracy. The Statue of Liberty was
    dedicated on October 28, 1886, designated as a National
    Monument in 1924 and restored for her centennial on July 4, 1986."""

attraction1 = Attraction(user_id=1,
                         name="Statue of Liberty",
                         description=description1,
                         city=city1)
print allCityNames

allEventNames = session.query(Event.city_id).all()
print allEventNames




# Clear database tables - City and Event
session.query(City).delete()
session.query(Event).delete()
session.commit()


# City info for San Francisco
city1 = City(name = "San Francisco", state="California")

session.add(city1)
session.commit()


event1 = Event(name = "Droidcon San Francisco 2015", description = "The droidcon conferences around the world support the Android platform and create a global network for developers and companies. We offer best-in-class presentations from leaders in all parts of the Android ecosystem, including core development, embedded solutions augmented reality, business solutions and games.", city = city1)

session.add(event1)
session.commit()

event2 = Event(name = "SF Android User Group", description = "We are an interactive group of Android developers and contractors discussing trends in technology, business, and job outlook.", city = city1)

session.add(event2)
session.commit()
def addCity(cityName):
    session = DBSession()
    newCity = City(name=cityName)
    session.add(newCity)
    session.commit()
Beispiel #12
0
# 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 based on Udacity's lecture code example
User1 = User(name="Robo Barista", email="*****@*****.**")
session.add(User1)
session.commit()

# Add four major cites in Texas
austin = City(name="Austin")
session.add(austin)
session.commit()

dallas = City(name="Dallas")
session.add(dallas)
session.commit()

houston = City(name="Houston")
session.add(houston)
session.commit()

sanantonio = City(name="San Antonio")
session.add(sanantonio)
session.commit()
Beispiel #13
0
session.query(Event).delete()
session.commit()

# Create initial user for adding data
User1 = User(
    name="TW",
    email="*****@*****.**",
    picture=
    'https://lh6.googleusercontent.com/-VnxWuzSW494/UEiyeA06zoI/AAAAAAAAWtU/LOxkmbmhFV8/w461-h460/photo-7c.png'
)
session.add(User1)
session.commit()
print User1.name

# City info for San Francisco
city1 = City(user_id=1, name="San Francisco", state="California")
session.add(city1)
session.commit()

event1 = Event(
    user_id=1,
    name="Droidcon San Francisco 2016",
    description="The droidcon conferences around the world support the \
	Android platform and create a global network for developers and \
	companies. We offer best-in-class presentations from leaders in all \
	parts of the Android ecosystem, including core development, embedded \
	solutions augmented reality, business solutions and games.",
    city=city1,
    event_date=date(2016, 3, 17),
    event_url="http://sf.droidcon.com/",
    image_url="https://embed.gyazo.com/11e1eaa28bf28afaa3a1f235b5f985e6.png")
Beispiel #14
0
# 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="Jhon Doe",
             email="*****@*****.**",
             picture='https://imgplaceholder.com/150x150')
session.add(user1)
session.commit()

city1 = City(name="Mecca", user=user1)

session.add(city1)
session.commit()

place1 = Place(
    name="Grand Mosque (Haram)",
    description=
    "The grand mosque of Makkah commonly known as Masjid al-Haram is the largest mosque in the world surrounded by the holiest places of Islam. Muslims around the world pray in the direction of Grand Mosque, 5 times a day",
    city=city1,
    user=user1)

session.add(place1)
session.commit()

city2 = City(name="Cairo", user=user1)
Beispiel #15
0
                "picture": "https://s3.amazonaws.com/files.collageplatform.com.prod/image_cache/1010x580_fit/57e1a75587aa2c703cbd6ecf/6630861cad0ef3f5be2e7f63349eb032.jpeg"
            },
            {
                "name": "Nakagin Capsule Tower",
                "description": "Architect: Kisho Kurokawa",
                "picture": "https://upload.wikimedia.org/wikipedia/commons/thumb/2/26/Nakagin.jpg/640px-Nakagin.jpg"
            }
        ]
    }
}
""")

# Add Cities in city_json to database
for e in city_json['Cities']:
    city_input = City(name=str(e['name']),
                      description=str(e['description']),
                      user=User1)
    session.add(city_input)
    session.commit()

# Add Architectures in city_json to database
for c in city_json['Architectures'].keys():
    city = session.query(City).filter_by(name=c).one()
    for e in city_json['Architectures'][c]:
        architecture_input = Architecture(name=str(e['name']),
                                          description=str(e['description']),
                                          picture=str(e['picture']),
                                          city=city,
                                          user=User1)
        session.add(architecture_input)
        session.commit()