Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correct_urlencode #62

Merged
merged 4 commits into from
Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions fast_bitrix24/mult_request.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import more_itertools
import asyncio
import php
import itertools

from .utils import convert_dict_to_bitrix_url
from .srh import BITRIX_MAX_BATCH_SIZE
from .server_response import ServerResponse

Expand All @@ -26,12 +25,13 @@ async def run(self):

def prepare_batches(self):
batch_size = BITRIX_MAX_BATCH_SIZE
builder = php.Php()

batches = [{
'halt': 0,
'cmd': {
self.batch_command_label(i, item):
f'{self.method}?{convert_dict_to_bitrix_url(item)}'
f'{self.method}?{builder.http_build_query(item)}'
for i, item in enumerate(next_batch)
}}
for next_batch in more_itertools.chunked(self.item_list, batch_size)
Expand Down
2 changes: 1 addition & 1 deletion fast_bitrix24/srh.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from tqdm import tqdm

from .server_response import ServerResponse
from .utils import convert_dict_to_bitrix_url, _url_valid
from .utils import _url_valid

BITRIX_POOL_SIZE = 50
BITRIX_RPS = 2.0
Expand Down
31 changes: 0 additions & 31 deletions fast_bitrix24/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,6 @@ def _url_valid(url):
return False


def convert_dict_to_bitrix_url(data):
parents = list()
pairs = list()

def renderKey(parents):
depth, outStr = 0, ''
for x in parents:
s = "[%s]" if (depth > 0 or isinstance(x, int)) and x!='[]' else "%s"
outStr += s % str(x)
depth += 1
return outStr

def r_urlencode(data):
if any(isinstance(data, t) for t in [list, tuple, set]):
data = list(data)
for i in range(len(data)):
parents.append('[]')
r_urlencode(data[i])
parents.pop()
elif isinstance(data, dict):
for key, value in data.items():
parents.append(key)
r_urlencode(value)
parents.pop()
else:
pairs.append((renderKey(parents), str(data)))

return pairs
return urllib.parse.urlencode(r_urlencode(data))


def _merge_dict(d1, d2):
d3 = d1.copy()
if d2:
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="fast_bitrix24",
version="0.4.3",
version="0.4.4",
author="Alexey Leshchenko",
author_email="leshchenko@gmail.com",
description="API wrapper для быстрого получения данных от Битрикс24 через REST API. Параллельные запросы к серверу, упаковка запросов в батчи, контроль скорости запросов.",
Expand All @@ -26,7 +26,8 @@
'aiohttp',
'asyncio',
'tqdm',
'more_itertools'
'more_itertools',
'php'
],
license="MIT"
)
17 changes: 15 additions & 2 deletions tests/test_.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ def delete_all_leads(get_test):


@pytest.fixture(scope='session')
def create_1000_leads(get_test):
def create_1000_leads(get_test, delete_all_leads):
b = get_test

delete_all_leads
with slow(1.2):
lead_nos = b.call('crm.lead.add', [{
'fields': {
Expand Down Expand Up @@ -51,14 +52,26 @@ def test_simple_add_lead(self, get_test):

def test_simple_get_all(self, get_test, delete_all_leads, create_1000_leads):
b = get_test
delete_all_leads
create_1000_leads

leads = b.get_all('crm.lead.list')

assert len(leads) == 1000


def test_get_all_params(self, get_test, create_1000_leads):
b = get_test
create_1000_leads

fields = ['ID', 'NAME']

leads = b.get_all('crm.lead.list', {
'select': fields
})

assert len(fields) == len(leads[0])


class TestLongRequests:

def test_long_task_description(self, get_test):
Expand Down