Пример #1
0
def scrape_name(request):
    # username = request.GET.get('username', None)
    i = 1080
    driver = ''
    while(i<=1086):
        try:
            option = webdriver.ChromeOptions()
            option.add_argument("window-size=1280,800")
            # option.add_argument("--headless")
            driver = webdriver.Chrome(ChromeDriverManager().install(), options=option)
            driver.get('https://sfera.sferabit.com/servizi/alboonlineBoot/index.php?id='+str(i))
            original_window = driver.current_window_handle
            # Check we don't have other windows open already
            assert len(driver.window_handles) == 1
            driver.switch_to.window(driver.window_handles[0])

            name_input = driver.find_element(By.ID, 'filtroRagioneSociale')
            name_input.send_keys('an')
            send_button = driver.find_element(By.CSS_SELECTOR, 'button.btn-primary')
            ActionChains(driver).move_to_element(send_button).click(send_button).perform()
            driver.implicitly_wait(10)
            td = driver.find_element(By.CSS_SELECTOR, '#risultatoRicerca>table.table tr>td:last-child').get_attribute('innerHTML')
            td = td.split(" ")[-2].strip()
            city = City(url_id=i, city_name=td)
            city.save()
        except:
            print(str(i)+" does not support")
        finally:
            i = i + 1
            driver.quit()
    data = {
        'is_taken': 'sdfsdfsdfsdfsdf'
    }
    return JsonResponse(data)
Пример #2
0
    def setUp(self):
        self.client = Client()

        # Add some cities and hotels in database for testing purposes
        City.objects.bulk_create([
            City(id='AMS', name='Amsterdam'),
            City(id='ANT', name='Antwerpen'),
            City(id='BER', name='Berlin'),
            City(id='BAR', name='Barcelona')
        ])
        Hotel.objects.bulk_create([
            Hotel(id='AMS909',
                  city=City.objects.get(id='AMS'),
                  name='Amsterdam Hotel'),
            Hotel(id='ANT77',
                  city=City.objects.get(id='ANT'),
                  name='Hotel Ant'),
            Hotel(id='ANT888',
                  city=City.objects.get(id='ANT'),
                  name='Second Hotel Ant'),
            Hotel(id='BAR8',
                  city=City.objects.get(id='BAR'),
                  name='Barcelona Hotel'),
            Hotel(id='BER22',
                  city=City.objects.get(id='BER'),
                  name='Berlin Hotel')
        ])
Пример #3
0
def populate_db():
    """Populates the cscourses.db database if it is empty. The Flask app needs to be running before you execute this code.

    :return: None
    """

    if not User.query.first():
        u1 = User( id=1, username="******", email='*****@*****.**')
        u2 = User( id=2, username="******", email="*****@*****.**")
        u3 = User( id=3, username="******", email="*****@*****.**")

        c1 = City( id=1, city="London" )
        c2 = City( id=2, city="Manchester" )

        f1 = Forecast( id=1, forecast="Rainy", forecast_datetime="2020-01-27 09:00:00",
                       comment="Take your umbrella !")

        u1.forecasts.append(f1)

        c1.forecasts.append(f1)

        db.session.add_all( [u1, u2, u3] )
        db.session.add_all( [c1, c2] )

        db.session.commit()
Пример #4
0
def deploy():
    """运行部署任务"""
    from flask.ext.migrate import upgrade
    upgrade()
    Role.insert_roles()
    City.insert_cities()
    Topic.insert_topics()
Пример #5
0
 def testImportCityFromCSVRow(self):
     row = ['Toronto', 'Ontario', 'Canada']
     City.import_from_csv_row(row)
     city = list(City.query())[0]
     self.assertEqual(city.name, 'Toronto')
     self.assertEqual(city.region, 'Ontario')
     self.assertEqual(city.country, 'Canada')
     self.assertEqual(city.nearby_cities, [])
Пример #6
0
def createdb():
    db.create_all()
    Role.insert_master()
    User.insert_master()
    Menu.insert_master()
    City.insert_master()
    R_User_City.insert_master()
    R_Role_Menu.insert_master()
    CityInfo.insert_master()
Пример #7
0
def deploy():
    import finaldata as fd
    db.drop_all()
    db.create_all()

    Country.insertCountries(fd.getCountries())
    City.insertCities(fd.getCities())
    Type.insertTypes(fd.getTypes())
    Museum.insertMuseums(fd.getMuseums())
    Period.insertPeriods(fd.getPeriods())
Пример #8
0
 def testImportCitiesFromCSVFile(self):
     rows = [
             ['City', 'Region', 'Country'],
             ['Toronto', 'Ontario', 'Canada'],
             ]
     csvfile = [','.join(row) for row in rows]
     City.import_from_csv(csvfile)
     city = list(City.query())[0]
     self.assertEqual(city.name, 'Toronto')
     self.assertEqual(city.region, 'Ontario')
     self.assertEqual(city.country, 'Canada')
Пример #9
0
    def parse(self, **kwargs):
        worksheet = GoogleSheetsParser.get_worksheet(self, '1Mp9r7CNxVnKip-tLAFpbGp4K_MY2iUrbrBOQBcsKLVE')

        i = 2
        while True:
            values_list = worksheet.row_values(i)
            i += 1

            if not values_list[0]:
                break

            try:
                country = Country.objects.get(
                    name=values_list[4]
                )
            except ObjectDoesNotExist:
                country = Country(
                    name=values_list[4]
                )
                self.country_count += 1
                country.save()

            try:
                region = Region.objects.get(
                    name=values_list[1]
                )
            except ObjectDoesNotExist:
                region = Region(
                    name=values_list[1],
                    country=country
                )
                self.region_count += 1
                region.save()

            try:
                city = City.objects.get(
                    name=values_list[0]
                )
            except ObjectDoesNotExist:
                city = City(
                    name=values_list[0],
                    lat=values_list[2],
                    lon=values_list[3],
                    region=region
                )
                self.city_count += 1
                city.save()

        return [
            'New Countries: ' + str(self.country_count),
            'New Regions: ' + str(self.region_count),
            'New Cities: ' + str(self.city_count),
        ]
Пример #10
0
def populate_db():
    c1 = City(name='Ithaca, NY')
    c2 = City(name='Binghamton, NY')
    c3 = City(name='Syracuse, NY')
    c4 = City(name='Rochester, NY')
    db.session.add_all([c1, c2, c3, c4])
    db.session.commit()
    a1 = Artist(name="Driftwood", description="Folk Rock", cityID=c2.id)
    a2 = Artist(name="Quail", description="Funk and Brass", cityID=c1.id)
    a3 = Artist(name="VeeDaBee", description="Rock Band", cityID=c1.id)
    a4 = Artist(name="Danielle Ponder", description="Soul", cityID=c4.id)
    db.session.add_all([a1, a2, a3, a4])
    db.session.commit()
    v1 = Venue(name='The Haunt', cityID=c2.id)
    v2 = Venue(name='State Theater', cityID=c1.id)
    v3 = Venue(name='Stewart Park', cityID=c1.id)
    v4 = Venue(name='University', cityID=c2.id)
    v5 = Venue(name='Oncenter', cityID=c3.id)
    db.session.add_all([v1, v2, v3, v4, v5])
    db.session.commit()
    e1 = Event(name='Ithaca Porchfest',
               time=datetime(2020, 11, 5, 20, 00),
               venueID=v3.id)
    e2 = Event(name='2020 Tour',
               time=datetime(2020, 10, 20, 18, 00),
               venueID=v5.id)
    e3 = Event(name='Anniversary Concert',
               time=datetime(2020, 10, 20, 19, 00),
               venueID=v1.id)
    e4 = Event(name='2020 Tour',
               time=datetime(2020, 10, 29, 18, 00),
               venueID=v2.id)
    e5 = Event(name='2020 Tour',
               time=datetime(2020, 10, 20, 12, 00),
               venueID=v4.id)
    db.session.add_all([e1, e2, e3, e4, e5])
    db.session.commit()
    x1 = ArtistToEvent(artistID=a1.id, eventID=e3.id)
    x2 = ArtistToEvent(artistID=a2.id, eventID=e3.id)
    x3 = ArtistToEvent(artistID=a1.id, eventID=e1.id)
    x4 = ArtistToEvent(artistID=a3.id, eventID=e4.id)
    x5 = ArtistToEvent(artistID=a4.id, eventID=e5.id)
    x6 = ArtistToEvent(artistID=a3.id, eventID=e2.id)
    db.session.add_all([x1, x2, x3, x4, x5, x6])
    db.session.commit()
    u1 = User(username='******',
              email=('*****@*****.**'),
              password_hash='Password')
    db.session.add(u1)
    db.session.commit()
    return render_template('base.html', title='Populate DB')
Пример #11
0
class TestImportPlaces(unittest.TestCase):
    
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        
        self.example_city = City(name='Toronto',
                                 region='Ontario',
                                 country='Canada')
        self.example_city.put()

    def testImportPlaceFromCSVRow(self):
        row = ['Title', 'URL', 'cat1 cat2', 'Address',
               self.example_city.name,
               self.example_city.region,
               self.example_city.country]
        Place.import_from_csv_row(row)
        place = list(Place.query())[0]
        self.assertEqual(place.title, 'Title')
        self.assertEqual(place.url, 'URL')
        self.assertEqual(place.categories, ['cat1', 'cat2'])
        self.assertEqual(place.address, 'Address')
        self.assertEqual(place.city, self.example_city.key)
        
    def testImportPlacesFromCSVFile(self):
        rows = [
                ['Title', 'URL', 'Categories (space-separated)', 'Address', 'City', 'Region', 'Country'],
                ['my place', 'place.com', 'cat1 cat2', '11 Rudolf Drive',
                 self.example_city.name, self.example_city.region, self.example_city.country],
                ]
        csvfile = [','.join(row) for row in rows]
        Place.import_from_csv(csvfile)
        place = list(Place.query())[0]
        self.assertEqual(place.title, 'my place')
        self.assertEqual(place.url, 'place.com')
        self.assertEqual(place.categories, ['cat1', 'cat2'])
        self.assertEqual(place.address, '11 Rudolf Drive')
        self.assertEqual(place.city, self.example_city.key)
        
    def testPlaceNotImportedWhenCityDoesNotExist(self):
        row = ['Title', 'URL', 'cat1 cat2', 'Address',
               self.example_city.name + '....',
               self.example_city.region,
               self.example_city.country]
        Place.import_from_csv_row(row)
        places = list(Place.query())
        self.assertEqual(len(places), 0)
Пример #12
0
def login(request):
    users = Users.objects.all()
    email = request.POST.get('email')
    password = request.POST.get('password')
    token_push = request.POST.get('token_push')
    i = 0
    for user in users:
        if users[i].mailUser == email:
            if users[i].passwordUser == password:
                if users[i].token_push == token_push:
                    userProfile = UserProfile.objects.filter(
                        idUser=users[i].UserProfile_userId)
                    pictures = Pictures.objects.filter(
                        idUserProfile=users[i].Pictures_idUserProfile)
                    city = City.objects.filter(idUser=users[i].City_idUser)
                    user = User(
                        users[i].idUser, userProfile.nameUserProfile,
                        users[i].mailUser, userProfile.ageUserProfile,
                        userProfile.genderUserProfile,
                        City(city.default, city.current),
                        Photos(pictures.picture01, pictures.picture02,
                               pictures.picture03))
                    loginResponse = LoginResponse(token_push, user)
                    return JsonResponse(loginResponse.getDict())
        ++i
    return HttpResponse('No sucess')
Пример #13
0
    def test_save_user_search(self, client, init_database):
        #Save a user search that already exists
        utils.save_user_search(1, 'South Park', 39.22, -105.99)
        #Count may return 2
        assert UserSearch.query.filter_by(user_id=1,
                                          city_id=1).first().count == 2

        #Save a new user search with a existant city
        #Test that the user search doesn't exists already
        assert UserSearch.query.filter_by(user_id=1, city_id=4).first() is None
        city = City(name='Cheyenne', lat=41.13, lon=-104.80)
        db.session.add(city)
        db.session.commit()
        utils.save_user_search(1, 'Cheyenne', 41.13, -104.80)
        #Then test that the user search exists
        assert UserSearch.query.filter_by(user_id=1,
                                          city_id=4).first() is not None

        #Save a new user search with a non existant city
        #Test that the user search doesn't exists already
        assert UserSearch.query.filter_by(user_id=1, city_id=5).first() is None
        utils.save_user_search(1, 'Fort Collins', 40.55, -105.04)
        #Then test that the user search exists
        assert UserSearch.query.filter_by(user_id=1,
                                          city_id=5).first() is not None
Пример #14
0
def beenNew():
    form = NewBeen()
    if form.validate_on_submit():
        type = 1
        blog = form.blog.data
        startDate = form.startDate.data
        endDate = form.endDate.data
        user=current_user.id

        country = form.country.data
        country = string.capwords(country)
        if Country.query.filter_by(name=form.country.data).first() is not None:
            c = Country.query.filter_by(name=form.country.data).first()
        else:
            c = Country(name=form.country.data)
            db.session.add(c)
            db.session.commit()
        city = form.city.data
        city = string.capwords(city)
        if City.query.filter_by(name=form.country.data).first() is not None:
            city1 = City.query.filter_by(name=form.country.data).first()
        else:
            city1 = City(name=city, countryID=c.id)
            db.session.add(city1)
            db.session.commit()

        p = Post(type=type, blog=blog, StartDate=startDate, EndDate=endDate, cityID=city1.id, userID=user)
        db.session.add(p)
        db.session.commit()
        flash('Blog Posted')
        return redirect('/beenList')

    return render_template('beenNew.html', title='New Been Post', form=form)
Пример #15
0
def index_post():
          new_city = request.form.get('city')

          err_msg = ''
          existing_city = City.query.filter_by(name=new_city).first()
     
     
          if not existing_city:
               new_city_data = get_weather_data(new_city)

               if new_city_data['cod'] == 200:
                         new_city_obj  = City(name=new_city)
                         db.session.add(new_city_obj)
                         db.session.commit()
               else:
                         err_msg = 'City does not exist in the world!'
          else:
               err_msg: "City Already Exists"

          if err_msg:
               flash(err_msg, 'error')
          else:
               flash('City added succesfully!')

   
          return redirect(url_for('index_get'))
def index_cities():
    with open('resources/cities/all_cities.csv', 'r') as f:
        reader = csv.reader(f)
        for row in reader:
            city = City(row[0], row[1])
            db.session.add(city)
            db.session.commit()

    with open('resources/cities/europe.csv', 'r') as f:
        reader = csv.reader(f)
        for row in reader:
            c = Europe(row[0])
            db.session.add(c)
            db.session.commit()

    with open('resources/cities/no_cal.csv', 'r') as f:
        reader = csv.reader(f)
        for row in reader:
            c = noCal(row[0])
            db.session.add(c)
            db.session.commit()

    with open('resources/cities/so_cal.csv', 'r') as f:
        reader = csv.reader(f)
        for row in reader:
            c = soCal(row[0])
            db.session.add(c)
            db.session.commit()

    with open('resources/cities/seasia.csv', 'r') as f:
        reader = csv.reader(f)
        for row in reader:
            c = SEAsia(row[0])
            db.session.add(c)
            db.session.commit()

    remote = [('REMOTE', 'REMOTE'), ('NO REMOTE', '_remote_'),
              ('REMOTE no', '_remote_'), ('Remote', '_remote_'),
              ('Remote not', '_remote_'), ('No Remote', '_remote_')]

    for i in remote:
        c = City(unicode(i[0]), unicode(i[1]))
        db.session.add(c)
        db.session.commit()
    db.session.close()
Пример #17
0
def _get_city_by_name(city):
    r = requests.get(API_CITY_ID_URL.format(city))

    data = r.json()
    if data:
        # return first result found
        return City().from_dict(r.json()[0])
    else:
        raise LookupError('{} city not found'.format(city))
Пример #18
0
def add_city():
    data = request.get_json()
    city = City(gp_id=data.get('gp_id'),
                name=data.get('name'),
                lat=data.get('lat'),
                lng=data.get('lng'))
    db.session.add(city)
    db.session.commit()
    return jsonify(status='OK')
Пример #19
0
def genfake():
    config = os.getenv('FLASK_CONFIG') or 'default'
    if config == 'default' or config == 'development':
        print("delete all files ...")
        db.drop_all()
        db.create_all()
        print("creating roles ...")
        Role.insert_roles()
        print("creating cities ...")
        City.insert_cities()
        print("creating topics ...")
        Topic.insert_topics()
        print("creating users ...")
        User.generate_fake()
        print("creating conferences ...")
        Conference.generate_fake()
        print("creating comments ...")
        Comment.generate_fake()
Пример #20
0
 def setUp(self):
     self.testbed = testbed.Testbed()
     self.testbed.activate()
     self.testbed.init_datastore_v3_stub()
     self.testbed.init_memcache_stub()
     
     self.example_city = City(name='Toronto',
                              region='Ontario',
                              country='Canada')
     self.example_city.put()
Пример #21
0
def populate_db():
    """Populates the rain.db database if it is empty

    :return: None
    """

    if not User.query.first():
        db.session.add_all([
            User(user_id=123, username='******', email='*****@*****.**'),
            User(user_id=404, username="******", email="*****@*****.**"),
            User(user_id=456, username="******", email="*****@*****.**"),
            User(user_id=888, username="******", email="*****@*****.**")
        ])

    if not City.query.first():
        db.session.add_all([
            City(city_id=10001, city_name="London"),
            City(city_id=10002, city_name="Seoul")
        ])

    if not Forecast.query.first():
        db.session.add_all([
            Forecast(forecast_id=1234,
                     datetime="2020-02-20",
                     forecast="Sunny",
                     comment="Today is a very sunny day",
                     city_id=10001,
                     user_id=123),
            Forecast(forecast_id=1235,
                     datetime="2020-02-19",
                     forecast="Cloudy",
                     comment="Very cloudy, no sun.",
                     city_id=10002,
                     user_id=404),
            Forecast(forecast_id=1236,
                     datetime="2020-02-18",
                     forecast="Windy",
                     comment="Wind speed 50 mph!",
                     city_id=10001,
                     user_id=888)
        ])

    db.session.commit()
Пример #22
0
def seed_cities():

    austin = City(name='Austin',
                  photo='../../react-app/src/resources/austin.png',
                  lat="30.267071088546306",
                  lng="-97.74654428141095")
    denver = City(name='Denver',
                  photo='../../react-app/src/resources/denver.jpg',
                  lat="39.73733106711871",
                  lng="-104.98214927100975")
    seattle = City(name='Seattle',
                   photo='../../react-app/src/resources/seattle.jpg',
                   lat="47.605536396351354",
                   lng="-122.33108563970562")

    db.session.add(austin)
    db.session.add(denver)
    db.session.add(seattle)

    db.session.commit()
Пример #23
0
def get_or_create_city(city_name, region):
    session = db_session()
    city = session.query(City).filter_by(name=city_name, region_id=region.id).first()
    if not city:
        new_city = City(name=city_name, region_id=region.id)
        session.add(new_city)
        session.commit()
        session.expunge_all()
        session.close()
        return new_city
    session.expunge_all()
    session.close()
    return city
Пример #24
0
    def test_city_model(self):
        """
        Test number of records in City table
        """

        # create test city
        city = City(name="IT", description="The IT City")

        # save city to database
        db.session.add(city)
        db.session.commit()

        self.assertEqual(City.query.count(), 1)
def upgrade():
    op.execute('COMMIT')
    with open('data/cities.csv', mode='r') as file:
        reader = DictReader(file)
        for row in reader:
            city = City(id=row['id'], name=row['name'], param=row['param'])
            db.session.add(city)
    with open('data/positions.csv', mode='r') as file:
        reader = DictReader(file)
        for row in reader:
            position = Position(id=row['id'], name=row['name'], param=row['param'])
            db.session.add(position)

    db.session.commit()
Пример #26
0
def init_cities(game_id):

    print("init cities")
    num_cities = City.query.count()
    if num_cities == 0:
        for city in start_cities:
            newcity = City(name=city['name'],
                           population=city['population'],
                           daily_consumption=city['daily_consumption'],
                           column=city['column'],
                           row=city['row'],
                           layer=city['layer'])
            db.session.add(newcity)
        db.session.commit()
    return 0
Пример #27
0
def add_country():
    filename = os.path.join(os.getcwd(), 'misc/nigeria.json')
    file_content = ''
    with open(filename, 'r') as rb:
        for line in rb:
            file_content += line
    obj = json.loads(file_content)
    country = Country(name='Nigeria')
    for i in obj:
        state = State(name=i)
        for k in obj[i]:
            city = City(name=k)
            state.cities.append(city)
        country.states.append(state)
    db.session.add(country)
    db.session.commit()
Пример #28
0
def init_cities(game):
    num_cities = City.query.filter_by(id_game=game.id).count()

    if num_cities == 0:
        for city in start_cities:
            newcity = City(id_game=game.id,
                           name=city['name'],
                           population=city['population'],
                           daily_consumption=city['daily_consumption'],
                           column=city['column'],
                           row=city['row'],
                           layer=city['layer'])
            db.session.add(newcity)

        # Commit (write to database) all the added records.
        db.session.commit()
    return True
Пример #29
0
def add_record():
    form = AddForm()
    if form.validate_on_submit():
        # Extract values from form
        city_name = form.city.data
        population = form.population.data

        # Create a city record to store in the DB
        c = City(city=city_name, population=population)

        # add record to table and commit changes
        db.session.add(c)
        db.session.commit()

        form.city.data = ''
        form.population.data = ''
        return redirect(url_for('add_record'))
    return render_template('add.html', form=form)
Пример #30
0
def init_database():
    """Create an instance of flask app with a test db"""
    db.create_all()

    #Insert 1 user, 1 city an 1 search
    user = User(username='******', email='*****@*****.**')
    user.set_password('password')
    city = City(name='South Park', lat=39.22, lon=-105.99)
    db.session.add(user)
    db.session.add(city)
    search = UserSearch(user_id=1, city_id=1, count=1)
    db.session.add(search)

    db.session.commit()

    yield db

    db.drop_all()
Пример #31
0
def city_create():
    form = PlaceForm()
    if form.validate_on_submit():

        find_city = City.query.filter_by(name=form.name.data).first()
        if find_city is not None:
            flash('Город с таким именем уже существует', 'danger')
            return redirect(url_for('.city_view'))

        city = City(name=form.name.data)
        db.session.add(city)
        db.session.commit()

        flash('Новый город добавлен', 'success')
        return redirect(url_for('.city_view'))

    return render_template('place/form.html',
                           form=form,
                           title='Добавление города')
Пример #32
0
def insert_data(path):
    with open(path, 'r', encoding='utf-8') as json_file:
        json_file_text = json_file.read()
        json_text = json.loads(json_file_text)
        for keys in json_text.keys():
            print(keys)
            province = Province(name=keys)
            db.session.add(province)
            db.session.commit()
            for key2 in json_text[keys].keys():
                print('\t' + key2, end='\n\t\t')
                city = City(name=key2, province_id=province.id)
                db.session.add(city)
                db.session.commit()
                for index in json_text[keys][key2]:
                    print(index, end=', ')
                    area = Area(name=index, city_id=city.id)
                    db.session.add(area)
                    db.session.commit()
            print('\n')
Пример #33
0
def sign(request):
    users = Users.objects.all()
    email = request.POST.get('email')
    name = request.POST.get('name')
    password = request.POST.get('password')
    token_push = request.POST.get('token_push')
    age = request.POST.get('age')
    gender = request.POST.get('gender')
    defaultCity = request.POST.get('defaultCity')
    currentCity = request.POST.get('currentCity')
    photo1 = request.POST.get('photo1')
    photo2 = request.POST.get('photo2')
    photo3 = request.POST.get('photo3')
    i = 0

    userProfileObj = UserProfile(nameUserProfile=name,
                                 genderUserProfile=gender,
                                 ageUserProfile=age)
    userProfileObj.save()
    userProfileObj = UserProfile.objects.get(nameUserProfile=name,
                                             genderUserProfile=gender,
                                             ageUserProfile=age)

    cityObj = City(default=defaultCity, current=currentCity)
    picturesObj = Pictures(picture01=photo1,
                           picture02=photo2,
                           picture03=photo3)
    userObj = Users(mailUser=email,
                    passwordUser=password,
                    token_push=token_push,
                    UserProfile_idUser=userProfileObj,
                    Pictures_idUserProfile=picturesObj.idUserProfile,
                    City_idUser=cityObj.idUser)
    userObj.save()
    user = User(userObj.idUser, userObj.nameUser, userObj.mailUser,
                userProfileObj.ageUserProfile,
                userProfileObj.genderUserProfile,
                CityResponse(cityObj.default, cityObj.current),
                Photos(photo1, photo2, photo3))
    loginResponse = LoginResponse(token_push, user)
    return JsonResponse(loginResponse.getDict())
Пример #34
0
def save():

    if request.method == 'POST':
        new_city = request.form.get('city')
        new_city_obj = City(name=new_city)

        if new_city:
            db.session.add(new_city_obj)
            db.session.commit()

    page = request.args.get('page', 1, type=int)
    cities = City.query.order_by(City.date_posted.desc()).all()

    url = 'http://api.openweathermap.org/data/2.5/weather?q={}&units=metric&appid={}'

    weather_data = []

    api_key = 'a778d9642410a11ed2cbd17c20c246bc'

    for city in cities:

        r = requests.get(url.format(city.name, api_key)).json()

        weather = {
            'city': city.name,
            'temperature': r['main']['temp'],
            'description': r['weather'][0]['description'],
            'icon': r['weather'][0]['icon'],
        }

        weather_data.append(weather)

    page = request.args.get('page', type=int)
    places = City.query.order_by(City.date_posted.desc())\
        .paginate(page = page, per_page=3)

    return render_template('save.html',
                           weather_data=weather_data,
                           cities=places)
Пример #35
0
def add_record():
    form = AddCityForm()
    if form.validate_on_submit():
        # Extract values from form
        city_name = form.city.data
        population = form.population.data
        country = form.country.data

        country_obj = db.session.query(Country).filter_by(
            country = country).first()

        print(country_obj, file=sys.stderr)
        # Create a city record to store in the DB
        c = City(city=city_name, population=population, country=country_obj)

        # add record to table and commit changes
        db.session.add(c)
        db.session.commit()

        form.city.data = ''
        form.population.data = ''
        return redirect(url_for('view_cities'))
    return render_template('add_city.html', form=form)
Пример #36
0
def add_city():
    """Добавить области в БД. Запустить только один раз!"""
    raions = ('Алексинский район', 'Арсеньевский район', 'Белёвский район',
              'Богородицкий район', 'Венёвский район', 'Воловский район',
              'Дубенский район', 'Ефремовский район', 'Заокский район',
              'Каменский район', 'Кимовский район', 'Киреевский район',
              'Куркинский район', 'Ленинский район', 'Новомосковский район',
              'Одоевский район', 'Плавский район', 'Суворовский район',
              'Тёпло-Огарёвский район', 'Узловский район', 'Чернский район',
              'Щёкинский район', 'Ясногорский район')
    region = Region()
    region.name = 'Тульская область'
    region.save()
    for raion in raions:
        city = City()
        city.region = region
        city.name = raion
        city.save()
Пример #37
0
def new_artists():
    form = AddNewArtistForm()

    if form.validate_on_submit():
        new_artist = form.new_artist.data
        if Artist.query.filter_by(name=new_artist).first() is not None:
            flash('Artist Already Exists')
            return redirect('artists/' + new_artist)
        flash('New Artist Page Created for {}'.format(form.new_artist.data))

        if City.query.filter_by(name=form.town.data).first() is not None:
            city = City.query.filter_by(name=form.town.data).first()
        else:
            city = City(name=form.town.data)
        db.session.add(city)
        db.session.commit()
        a1 = Artist(name=new_artist,
                    description=form.description.data,
                    cityID=city.id)
        db.session.add(a1)
        db.session.commit()
        return redirect('artists/' + new_artist)

    return render_template('new_artists.html', title='New Artist', form=form)
Пример #38
0
 def form_valid(self):
     lines = self.form['file'].splitlines()
     City.import_from_csv(lines)