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

Possible refactor? downloads + post requests #118

Open
tarakc02 opened this issue Sep 18, 2024 · 3 comments
Open

Possible refactor? downloads + post requests #118

tarakc02 opened this issue Sep 18, 2024 · 3 comments

Comments

@tarakc02
Copy link
Collaborator

utils.get_url and utils.post_url contain a lot of duplicated code, we thought we could simplify by turning them into one method.

@naumansharifwork
Copy link
Contributor

@tarakc02 @stucka @newsroomdev
Our current download method uses the get_request , where ever we need to download the files with the post_request currently we are writing them into respective scrapers which is causing a bit of extra code.

There are 2 ways that i proposed that will help us to refactor this

  • FIrst is In the arguments of the download function we pass another argument called request_method with the default value of GET. and apply an if condition in the download function to use the get_function when there is no value passed or get is passed, Otherwise use the post_request function
  • The second way is we create a separate download function in utils that uses the post method, we can name the function something as download_post or something more clear.

Let me know what others think about this, or any other ideas.

@stucka
Copy link
Contributor

stucka commented Sep 19, 2024

A lot of the time it's going to be a one-line fix, to call cache.write_binary to save the contents. But that skips the download functionality of force, which is handy.

@naumansharifwork , I like your first proposal -- it's elegant and clean and makes a ton of sense. as long as a "data"/payload can be passed through kwargs, I think it's great.

I'd also again urge we consider bumping up the download buffer size to something like 1024*1024 from the existing 8192. =)

@stucka
Copy link
Contributor

stucka commented Sep 19, 2024

Oh, and if we're stripping any functionality of existing libraries we'll need to know what's using that functionality and how/when/who refactors the code. If the code is stable and fully functional and already used, there might not be a real reason to remove it ... ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@stucka @tarakc02 @naumansharifwork and others