Ejemplo n.º 1
0
def update_countries_and_payment_methods():
    # обновляем список стран и методов оплаты, привязываем методы оплаты к стране и обменнику
    model = ExchangeService()
    model.set_countries()
    model.set_payment_methods()
    model.set_payment_methods_by_country_codes()
    session.clear()
    return True
Ejemplo n.º 2
0
 def update_countries():
     test = ExchangeService()
     test.set_countries()
     test.set_payment_methods()
     test.set_payment_methods_by_country_codes()
     with open('app/files/cities.json', encoding="utf8") as json_file:
         data = json.load(json_file)
     for value in data:
         city = Cities()
         city.country_code = value['country']
         city.city_name = value['name']
         city.lat = value['lat']
         city.lng = value['lng']
         db.session.add(city)
     db.session.commit()
     session.clear()
     return redirect(url_for('admin.index'))
Ejemplo n.º 3
0
def update_rates():
    # обновляем статиститку по обменникам + добавляем новые валюты, если они есть
    exchange_service_model = ExchangeService()
    exchange_service_model.set_rates()
    session.clear()
    return True
Ejemplo n.º 4
0
 def __init__(self):
     self.cache = SimpleCache()
     self.exchange_service = ExchangeService()
Ejemplo n.º 5
0
class CacheService:
    def __init__(self):
        self.cache = SimpleCache()
        self.exchange_service = ExchangeService()

    def set_currency_count(self):
        currency_count = self.cache.get('currency_count')
        if currency_count is None:
            currency_count = self.exchange_service.get_currency_count()
            self.cache.set('currency_count',
                           currency_count,
                           timeout=60 * 60 * 24 * 30)
        return currency_count

    def set_markets_count(self):
        market_count = self.cache.get('market_count')
        if market_count is None:
            market_count = self.exchange_service.get_market_count()
            self.cache.set('market_count',
                           market_count,
                           timeout=60 * 60 * 24 * 30)
        return market_count

    @staticmethod
    def set_sellers(code, data):
        engine = create_engine(database.connect)
        Session = scoped_session(
            sessionmaker(autocommit=False, autoflush=False, bind=engine))
        session = Session()
        sellers_cache = SellersCache.query.filter_by(code=code).first()
        if sellers_cache is None:
            sellers_cache = SellersCache()
            sellers_cache.code = code
            sellers_cache.data = data
            local_object = session.merge(sellers_cache)
            session.add(local_object)
            # db.session.add(sellers_cache)
        else:
            sellers_cache.data = data
            local_object = session.merge(sellers_cache)
            session.add(local_object)
            # db.session.add(sellers_cache)
        session.commit()
        session.close()
        # db.session.commit()
        return sellers_cache

    @staticmethod
    def get_sellers(code):
        return SellersCache.query.filter_by(code=code).first()

    @staticmethod
    def set_buyers(code, data):
        engine = create_engine(database.connect)
        Session = scoped_session(
            sessionmaker(autocommit=False, autoflush=False, bind=engine))
        session = Session()
        buyers_cache = BuyersCache.query.filter_by(code=code).first()
        if buyers_cache is None:
            buyers_cache = BuyersCache()
            buyers_cache.code = code
            buyers_cache.data = data
            local_object = session.merge(buyers_cache)
            session.add(local_object)
            # db.session.add(buyers_cache)
        else:
            buyers_cache.data = data
            local_object = session.merge(buyers_cache)
            session.add(local_object)
            # db.session.add(buyers_cache)
        # db.session.commit()
        session.commit()
        session.close()
        return buyers_cache

    @staticmethod
    def get_buyers(code):
        return BuyersCache.query.filter_by(code=code).first()
Ejemplo n.º 6
0
 def buy_btc(self, params):
     exchangeService = ExchangeService()
     country = CountryRepository()
     methods = PaymentMethodRepository()
     currency = CurrencyRepository()
     countries = country.get_all()
     payment_methods = methods.get_all()
     currencies = currency.get_fiat_currencies()
     count = None
     country_id = country_id_cash = method_id = currency_id = city = None
     h = []
     values = []
     refferals = []
     if params is not None:
         values = params.split('-')
     if values and values[0] == 'online':
         country_id = request.form.get('country_id')
         method_id = request.form.get('payment_method_id')
         currency_id = request.form.get('currency_id')
         if country_id is not None or method_id is not None or currency_id is not None:
             count = self.get_sellers(country_id, method_id, currency_id)
             refferals = exchangeService.get_refferals('online')
     if values and values[0] == 'cash':
         country_id_cash = request.form.get('country_id_cash')
         country_find = Countries.query.filter(
             Countries.id == country_id_cash).first()
         cities_find = Cities.query.filter(
             Cities.country_code == country_find.name_alpha2).order_by(
                 Cities.city_name).all()
         for city in cities_find:
             h.append({'city_id': city.id, 'city_name': city.city_name})
         city = request.form.get('city_id')
         if city is not None:
             count = self.get_sellers_cash(city)
             refferals = exchangeService.get_refferals('cash')
     if values and values[0] == 'country':
         values.remove('country')
         country_find = Countries.query.filter(
             Countries.description == '-'.join(values)).first()
         country_id_one = country_find.id
         count = self.get_sellers(country_id_one, None, None)
     if values and values[0] == 'payment':
         values.remove('payment')
         values.remove('method')
         method_find = PaymentMethods.query.filter(
             PaymentMethods.slug == '-'.join(values)).first()
         method_id_one = method_find.id
         count = self.get_sellers(None, method_id_one, None)
     if values and values[0] == 'currency':
         values.remove('currency')
         currency_find = Currencies.query.filter(
             Currencies.slug == '-'.join(values)).first()
         currency_id_one = currency_find.id
         count = self.get_sellers(None, None, currency_id_one)
     select = {
         'country': country_id,
         'method': method_id,
         'currency': currency_id,
         'country_cash': country_id_cash,
         'city': city,
         'cities': h
     }
     return render_template("buy_currency.html",
                            title='Buy Bitcoins',
                            data=countries,
                            methods=payment_methods,
                            currencies=currencies,
                            count=count,
                            select=select,
                            refferals=refferals)
Ejemplo n.º 7
0
 def update_rates():
     exchange_service_model = ExchangeService()
     exchange_service_model.set_rates()
     session.clear()
     return redirect(url_for('stocks'))