def exchange(): countries = CountryRepository.get_all() methods = PaymentMethodRepository.get_all() return render_template('exchange.html', title='Exchange', countries=countries, methods=methods)
def get_buyers(self, country, method, currency): model = LocalbitcoinsService() country_find = CountryRepository.get_by_id(country) method_find = PaymentMethodRepository.get_by_id(method) currency_find = CurrencyRepository.get_by_id(currency) common_sellers = model.get_buyers(country_find, method_find, currency_find) thread_rate = threading.Thread(target=self.update_buyers_thread, args=( country, method, currency, )) thread_rate.daemon = True thread_rate.start() if common_sellers is None: return 0 return len(common_sellers.keys())
def update_buyers_thread(country, method, currency): bitcoin_service = LocalbitcoinsService() if bool(method): method_find = PaymentMethodRepository.get_by_id(method) method_sellers = bitcoin_service.sell_bitcoins_method( method_find.method) CacheService.set_buyers(method_find.method, json.dumps(method_sellers)) if bool(country): country_find = CountryRepository.get_by_id(country) country_sellers = bitcoin_service.sell_bitcoins_country( country_find.name_alpha2, country_find.description) CacheService.set_buyers(country_find.name_alpha2, json.dumps(country_sellers)) if bool(currency): currency_find = CurrencyRepository.get_by_id(currency) currency_sellers = bitcoin_service.sell_bitcoins_currency( currency_find.name.lower()) CacheService.set_buyers(currency_find.name.lower(), json.dumps(currency_sellers))
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)