Ejemplo n.º 1
0
    def setUp(self):
        self.c1 = Country.from_json([[[0, 0], [200, 200], [100, 300]]])
        self.c2 = Country.from_json([[[0, 0], [200, 0], [200, 200]]])

        self.c3 = Country.from_json([[[0, 0], [0, 300], [100, 300]]])
        self.c4 = Country.from_json([[[200, 200], [100, 300], [500, 500]]])
        self.c_map = Map([self.c1, self.c2, self.c3, self.c4])
Ejemplo n.º 2
0
 def setUp(self):
     self.target = Country(name='Gergovia')
     self.app = cimarron.skin.Application()
     self.window = cimarron.skin.Window(title='Test', parent=self.app)
     self.widget = self.entry = cimarron.skin.Entry(parent=self.window,
                                                    target=self.target,
                                                    attribute='name')
Ejemplo n.º 3
0
 def setUpControl(self, target=Country(name='Elbonia'), attr='name'):
     self.widget.attribute = self.attribute = attr
     self.target = target
     self.widget.newTarget(self.target)
     if attr is not None:
         self.value = getattr(target, attr)
     else:
         self.value = target
Ejemplo n.º 4
0
 def add_country(self):
     if self.points:
         self.pieces.append(CountryPiece(self.points))
         self.points = []
     if self.pieces:
         self.countries.append(Country(self.pieces))
         self.pieces = []
     self.trigger_sticky_point_mode()
     self.repaint()
Ejemplo n.º 5
0
 def get_country_list_geozones_page(self):
     wd = self.app.wd
     self.open_geozones_page()
     country_list = []
     for row in wd.find_elements_by_css_selector("tr.row"):
         cells = row.find_elements_by_css_selector("td")
         id = cells[1].text
         name = cells[2].text
         link = cells[2].find_element_by_css_selector("a").get_attribute("href")
         zones = cells[3].text
         country_list.append(Country(id=id, name=name, link=link, zones=zones))
     return list(country_list)
Ejemplo n.º 6
0
def new_country():
    """
    new_country() serves the page which lets the user create a country.

    :return: new country page template
    """

    if request.method == 'POST':
        inputs = request.form
        country = Country()
        country.user_id = login_session['user_id']

        if inputs['name']:
            country.name = inputs['name']
        if inputs['description']:
            country.description = inputs['description']

        db_helper.add_to_db(country)

        return redirect(url_for('home.home'))

    return render_template('newcountry.html')
Ejemplo n.º 7
0
    def register_address_by_names(self, street_name, neighbourhood, city_name,
                                  state_name, country_name):
        try:
            country = Country(name=country_name)
            db.session.add(country)
            db.session.commit()

        except exc.IntegrityError:
            db.session.rollback()
            country = Country.query.filter_by(name=country_name).first()

        try:
            state = State(name=state_name, country_id=country.id)
            db.session.add(state)
            db.session.commit()

        except exc.IntegrityError:
            db.session.rollback()
            state = State.query.filter(
                and_(State.name == state_name,
                     State.country_id == country.id)).first()

        try:
            city = City(name=city_name, state_id=state.id)
            db.session.add(city)
            db.session.flush()

        except exc.IntegrityError:
            db.session.rollback()
            city = City.query.filter(
                and_(City.name == city_name,
                     City.state_id == state.id)).first()

        try:
            address = Address(street_name=street_name,
                              neighbourhood=neighbourhood,
                              city_id=city.id)
            db.session.add(address)
            db.session.commit()

            return address.id

        except exc.IntegrityError:
            db.session.rollback()
            return None
Ejemplo n.º 8
0
def build_address(condominium_obj):
    try:
        country = Country(name=condominium_obj['CountryName'])
        db.session.add(country)
        db.session.flush()

    except exc.IntegrityError:
        db.session.rollback()
        country = Country.query.filter_by(
            name=condominium_obj['CountryName']).first()

    try:
        state = State(name=condominium_obj['StateName'], country_id=country.id)
        db.session.add(state)
        db.session.flush()

    except exc.IntegrityError:
        db.session.rollback()
        state = State.query.filter(
            and_(State.name == condominium_obj['StateName'],
                 State.country_id == country.id)).first()

    try:
        city = City(name=condominium_obj['CityName'], state_id=state.id)
        db.session.add(city)
        db.session.flush()

    except exc.IntegrityError:
        db.session.rollback()
        city = City.query.filter(
            and_(City.name == condominium_obj['CityName'],
                 City.state_id == state.id)).first()

    address = Address(street_name=condominium_obj['StreetName'],
                      neighbourhood=condominium_obj['Neighbourhood'],
                      city_id=city.id)
    db.session.add(address)
    db.session.flush()

    return address.id
Ejemplo n.º 9
0
admin = User(name='Bilbo Baggins', email="*****@*****.**")

session.add(admin)

# Create Brazil.
brazil = Country(
    user=admin,
    name="Brazil",
    description="Brazil, officially the Federative Republic of Brazil, "
    "is the largest country in both South America and Latin "
    "America. At 8.5 million square kilometers (3.2 million "
    "square miles) and with over 208 million people, Brazil is "
    "the world's fifth-largest country by area and the "
    "sixth-most populous. The capital is Brasília, and the "
    "most-populated city is São Paulo. It is the largest country "
    "to have Portuguese as an official language and the only one "
    "in the Americas. Bounded by the Atlantic Ocean on the east, "
    "Brazil has a coastline of 7,491 kilometers (4,655 mi). It "
    "borders all other South American countries except Ecuador "
    "and Chile and covers 47.3% of the continent's land area. "
    "Its Amazon River basin includes a vast tropical forest, "
    "home to diverse wildlife, a variety of ecological systems, "
    "and extensive natural resources spanning numerous protected "
    "habitats. This unique environmental heritage makes Brazil "
    "one of 17 megadiverse countries, and is the subject of "
    "significant global interest and debate regarding "
    "deforestation and environmental protection.")

session.add(brazil)

# Create Sugar Loaf and associate with Brazil.
sugar_loaf = Attraction(
Ejemplo n.º 10
0
    country_code = country_basic_info['countryCode']
    if country_code == '': # ip2country returns an object with empty fields if the given IP is private e.g. 192.168.1.1
        raise InvalidPublicIPError('Error: ' + ip + ' is a private IP')
    country_emoji = country_basic_info['countryEmoji']
    print 'Getting country data...'
    country_fields = ['name','languages','timezones','latlng','currencies']
    country_info = Countries().get_country_info(country_code=country_code, fields=country_fields)
    print 'Getting currency latest rate...'
    currency_code = country_info['currencies'][0]['code']
    currency_rate = ExchangeRates().get_latest_rate(currency_code=currency_code, base_currency_code='USD')

    # Build and populate country object
    country_currency = {'code': currency_code, 'rate_against_usd': currency_rate}
    country_location = {'lat': country_info['latlng'][0], 'lon': country_info['latlng'][1]}
    country = Country(code=country_code, name=country_info['name'], emoji=country_emoji,
    languages=country_info['languages'], currency=country_currency,
    timezones=country_info['timezones'], location=country_location)

    # Show info
    print ('\n\n')
    print('IP: ' + ip)
    country.print_name_and_emoji()
    country.print_code()
    country.print_languages()
    country.print_currency()
    country.print_time()
    country.print_distance(lat=-34.6, lon=-58.4)

except InvalidPublicIPError as e:
    print e.message
except Exception:
Ejemplo n.º 11
0
from model.group import Group
from model.keywordmodel import Keyword
from model.notifications import Notifications
from model.user import User
from model.suggestion import Suggestion
from model.favorite import Favorite
from model.message import Message
from model.statistic import Statistic
from model.statistic import track_activity
from model.ping import Ping
from model.revision import Revision

if __name__ == "__main__":
    Category.create_table(fail_silently=True)
    Bot.create_table(fail_silently=True)
    Country.create_table(fail_silently=True)
    Channel.create_table(fail_silently=True)
    User.create_table(fail_silently=True)
    Suggestion.create_table(fail_silently=True)
    Group.create_table(fail_silently=True)
    Notifications.create_table(fail_silently=True)
    Keyword.create_table(fail_silently=True)
    Favorite.create_table(fail_silently=True)
    APIAccess.create_table(fail_silently=True)

    APIAccess.insert({
        'user': User.get(User.username == 'Bfaschatsbot'),
        'token': '474609801:AAFrSFYP9YXPFa5OmQReEjTn6Rs44XQVuDM',
    }).execute()

    # Country.insert_many([
 def create(self, name):
     country = Country(name)
     self.db.insert(self.__serialize(country))
Ejemplo n.º 13
0
 def setUp(self):
     self.c1 = Country.from_json([[[0, 0], [200, 200], [100, 300]]])
     self.c2 = Country.from_json([[[0, 0], [200, 0], [200, 200]]])