From 5b2e4e5bd09905fd253d006bf1d5e8d2f4890a8d Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Fri, 13 May 2022 17:10:58 +0100 Subject: [PATCH] Move map provider function to upper level class --- handler/sources/local.py | 26 ++++++++++++++++++++++---- handler/sources/localbitcoins.py | 13 ------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/handler/sources/local.py b/handler/sources/local.py index 9319998..3a069a5 100644 --- a/handler/sources/local.py +++ b/handler/sources/local.py @@ -44,6 +44,19 @@ class Local(util.Base): self.lc_cheat.start(int(self.sets.CheatSec)) self.log.debug("Finished setting up loops.") + def map_provider(self, provider, reverse=False): + provider_map = {"NATIONAL_BANK": "national-bank-transfer"} + if reverse: + try: + return next(key for key, value in provider_map.items() if value == provider) + except StopIteration: + return False + else: + try: + return provider_map[provider] + except KeyError: + return False + @inlineCallbacks def got_dashboard(self, dash): dash_tmp = yield self.wrap_dashboard(dash) @@ -294,8 +307,8 @@ class Local(util.Base): # coin = "monero" # elif asset == "BTC": # coin = "bitcoins" - # if not providers: - # providers = ["NATIONAL_BANK"] + if not providers: + providers = ["NATIONAL_BANK"] # buy-monero-online, buy-bitcoin-online # Work around Agora weirdness calling it bitcoins # ads = yield self.api._api_call( @@ -306,6 +319,7 @@ class Local(util.Base): ads = yield self.api.buy_monero_online(currency_code=currency, page=page) elif asset == "BTC": ads = yield self.api.buy_bitcoins_online(currency_code=currency, page=page) + # with open("pub.json", "a") as f: # import json # f.write(json.dumps([page, currency, asset, ads])+"\n") @@ -319,7 +333,12 @@ class Local(util.Base): if "data" not in ads["response"]: return False for ad in ads["response"]["data"]["ad_list"]: - if ad["data"]["online_provider"] not in providers: + provider = ad["data"]["online_provider"] + if self.platform == "lbtc": + provider_test = self.map_provider(provider) + else: + provider_test = provider + if provider_test not in providers: continue date_last_seen = ad["data"]["profile"]["last_online"] # Check if this person was seen recently @@ -328,7 +347,6 @@ class Local(util.Base): ad_id = ad["data"]["ad_id"] username = ad["data"]["profile"]["username"] temp_price = ad["data"]["temp_price"] - provider = ad["data"]["online_provider"] if ad["data"]["currency"] != currency: continue to_append = [ad_id, username, temp_price, provider, asset, currency] diff --git a/handler/sources/localbitcoins.py b/handler/sources/localbitcoins.py index 505761f..0ba2c9d 100644 --- a/handler/sources/localbitcoins.py +++ b/handler/sources/localbitcoins.py @@ -29,19 +29,6 @@ class LBTC(sources.local.Local): # Assets that cheat has been run on self.cheat_run_on = [] - def map_provider(self, provider, reverse=False): - provider_map = {"NATIONAL_BANK": "national-bank-transfer"} - if reverse: - try: - return next(key for key, value in provider_map.items() if value == provider) - except StopIteration: - return False - else: - try: - return provider_map[provider] - except KeyError: - return False - @util.handle_exceptions def release_funds(self, contact_id): """