Begin implementing ad deduplication and re-enable releasing

This commit is contained in:
Mark Veidemanis 2023-04-18 11:25:56 +01:00
parent 84871d5a7c
commit 2b7e83dc0d
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
4 changed files with 44 additions and 15 deletions

View File

@ -200,6 +200,11 @@ urlpatterns = [
ads.AdRedist.as_view(), ads.AdRedist.as_view(),
name="ad_redist", name="ad_redist",
), ),
path(
"ops/ads/dedup/",
ads.AdDedup.as_view(),
name="ad_dedup",
),
path( path(
"ops/ads/cheat/", "ops/ads/cheat/",
ads.Cheat.as_view(), ads.Cheat.as_view(),

View File

@ -610,6 +610,7 @@ class LocalPlatformClient(ABC):
:rtype: bool or dict :rtype: bool or dict
""" """
dist_list = list(self.create_distribution_list(ad, filter_asset)) dist_list = list(self.create_distribution_list(ad, filter_asset))
print("Dist list", dist_list)
our_ads = await self.enum_ads() our_ads = await self.enum_ads()
( (
supported_currencies, supported_currencies,
@ -620,10 +621,12 @@ class LocalPlatformClient(ABC):
log.error("Could not get our ads") log.error("Could not get our ads")
return False return False
our_ads = [(x[0], x[2], x[3], x[4]) for x in our_ads] our_ads = [(x[0], x[2], x[3], x[4]) for x in our_ads]
print("our_ads", our_ads)
to_return = [] to_return = []
for asset, countrycode, currency, provider in dist_list: for asset, countrycode, currency, provider in dist_list:
if (asset, countrycode, currency, provider) not in our_ads: if (asset, countrycode, currency, provider) not in our_ads:
print("NOT IN OUR ADS", asset, countrycode, currency, provider)
if currency not in supported_currencies: if currency not in supported_currencies:
continue continue
# Create the actual ad and pass in all the stuff # Create the actual ad and pass in all the stuff
@ -692,7 +695,9 @@ class LocalPlatformClient(ABC):
:rtype: list :rtype: list
""" """
existing_ads = await self.enum_ads() existing_ads = await self.enum_ads()
print("EXISTING", existing_ads)
_size = len(existing_ads) _size = len(existing_ads)
print("SIZE", _size)
repeated = [] repeated = []
for i in range(_size): for i in range(_size):
k = i + 1 k = i + 1
@ -704,10 +709,12 @@ class LocalPlatformClient(ABC):
repeated.append(existing_ads[i]) repeated.append(existing_ads[i])
actioned = [] actioned = []
print("repeated", repeated)
for ad_id, country, currency in repeated: for ad_id, country, currency in repeated:
rtrn = await self.api.ad_delete(ad_id) rtrn = await self.api.ad_delete(ad_id)
actioned.append(rtrn["success"]) actioned.append(rtrn["success"])
print("actioned", actioned)
return all(actioned) return all(actioned)
async def release_trade_escrow(self, trade_id, reference): async def release_trade_escrow(self, trade_id, reference):
@ -716,21 +723,16 @@ class LocalPlatformClient(ABC):
title = "Releasing escrow" title = "Releasing escrow"
await notify.sendmsg(self.instance.user, logmessage, title=title) await notify.sendmsg(self.instance.user, logmessage, title=title)
# THIS IS NOT A COMMENT rtrn = await self.release_funds(trade_id)
# THIS IS FOR SECURITY if rtrn["message"] == "OK":
# WHEN IT HAS BEEN CONFIRMED TO WORK await self.api.contact_message_post(trade_id, "Thanks! Releasing now :)")
# THIS CAN BE UNCOMMENTED return True
# rtrn = await self.release_funds(trade_id) else:
# if rtrn["message"] == "OK": logmessage = f"Release funds unsuccessful: {rtrn['message']}"
# await self.api.contact_message_post(trade_id, "Thanks! Releasing now :)") title = "Release unsuccessful"
# return True log.error(logmessage)
# else: await notify.sendmsg(self.instance.user, logmessage, title=title)
# logmessage = f"Release funds unsuccessful: {rtrn['message']}" return
# title = "Release unsuccessful"
# log.error(logmessage)
# await notify.sendmsg(self.instance.user, logmessage, title=title)
# return
# UNCOMMENT TO HERE
async def update_trade_tx(self, stored_trade, tx_obj): async def update_trade_tx(self, stored_trade, tx_obj):
""" """

View File

@ -294,4 +294,5 @@ AdsSchema = {
"message": "message", "message": "message",
"ad_count": "response.data.ad_count", "ad_count": "response.data.ad_count",
"ad_list": "response.data.ad_list", "ad_list": "response.data.ad_list",
"pagination": "response.pagination",
} }

View File

@ -81,6 +81,19 @@ class AdRedist(LoginRequiredMixin, OTPRequiredMixin, View):
return render(request, self.template_name, context) return render(request, self.template_name, context)
class AdDedup(LoginRequiredMixin, OTPRequiredMixin, View):
template_name = "mixins/partials/notify.html"
def get(self, request):
platforms = get_platforms(request.user)
for platform in platforms:
run = synchronize_async_helper(AgoraClient(platform))
synchronize_async_helper(run.strip_duplicate_ads())
context = {"class": "success", "message": "Ads deduplicated"}
return render(request, self.template_name, context)
class AdList(LoginRequiredMixin, OTPRequiredMixin, ObjectList): class AdList(LoginRequiredMixin, OTPRequiredMixin, ObjectList):
list_template = "partials/ad-list.html" list_template = "partials/ad-list.html"
model = Ad model = Ad
@ -123,6 +136,14 @@ class AdList(LoginRequiredMixin, OTPRequiredMixin, ObjectList):
"icon": "fa-solid fa-bomb", "icon": "fa-solid fa-bomb",
"confirm": True, "confirm": True,
}, },
{
"url": reverse("ad_dedup"),
"action": "deduplicate",
"method": "get",
"label": "Deduplicate ads",
"icon": "fa-thin fa-copy",
"confirm": True,
},
] ]
return context return context