From: Radek Czajka Date: Mon, 9 May 2022 10:56:30 +0000 (+0200) Subject: Legimi sales. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/181848c12143b7a9160b8bb33c8c69cbd48864a2 Legimi sales. --- diff --git a/src/depot/legimi.py b/src/depot/legimi.py index 75ddaa12..8d2939e4 100644 --- a/src/depot/legimi.py +++ b/src/depot/legimi.py @@ -29,6 +29,7 @@ class Legimi: CREATE_URL = BASE_URL + '/publishers/publications/create' EDIT_URL = BASE_URL + '/publishers/publications/edit/%s' EDIT_FILES_URL = BASE_URL + '/publishers/publications/editfiles/%s' + EDIT_SALE_URL = BASE_URL + '/publishers/publications/editsale/%s' def __init__(self, username, password, publisher_id): self.username = username @@ -297,6 +298,42 @@ class Legimi: data=current ) + def edit_sale(self, book): + assert book.legimi_id + + words = book.wldocument().get_statistics()['total']['words_with_fn'] + + price = settings.LEGIMI_SMALL_PRICE + if words > settings.LEGIMI_SMALL_WORDS: + price = settings.LEGIMI_BIG_PRICE + + abo = 'true' if words > settings.LEGIMI_BIG_WORDS else 'false' + + data = { + 'ValidationTrue': 'true', + 'Id': book.legimi_id, + 'SalesPromotionId': "0", + 'IsLibraryPass': "False", + 'OriginalEnterToTheMarketType': "No", + 'OriginalHidingDate': "", + 'OriginalEnterToTheMarketDate': "", + 'EnterToTheMarketType': "No", + 'EnterToTheMarketDate': "", + 'HidingDate': "", + 'SalesNoLimitOption': abo, + 'SalesNoLimitKindle': abo, + 'SalesInStoreEbookGrossValue': f'{price},00', + 'SalesPromotion': "False", + 'SalesPromotionGrossValue': "0,00", + 'SalesPromotionDatesRange.DateStart': "", + 'SalesPromotionDatesRange.DateEnd': "", + } + + self.session.post( + self.EDIT_SALE_URL % book.legimi_id, + data=data + ) + legimi = Legimi( settings.LEGIMI_USERNAME, diff --git a/src/redakcja/settings/__init__.py b/src/redakcja/settings/__init__.py index 1570e636..01fb6cee 100644 --- a/src/redakcja/settings/__init__.py +++ b/src/redakcja/settings/__init__.py @@ -115,6 +115,11 @@ LOGIN_REDIRECT_URL = '/documents/user' MIN_COVER_SIZE = (915, 1270) +LEGIMI_SMALL_WORDS = 2000 +LEGIMI_BIG_WORDS = 10000 +LEGIMI_SMALL_PRICE = 7 +LEGIMI_BIG_PRICE = 20 + STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder',