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

Solution 2.2 Added #35

Closed
wants to merge 11 commits into from
Closed

Conversation

sciencepal
Copy link
Collaborator

Please Review @kaustubh-karkare

Copy link
Owner

@kaustubh-karkare kaustubh-karkare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Not sure why you needed to change the permissions of all files. Revert please.
  • Still need to fix style guide issues.

if (start_byte == 0 and end_byte == 0):
byte_range = ""
else:
byte_range = "Range: bytes=%s-%s\r\n" %(str(start_byte), str(end_byte))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space after %. Also violates line length limit.

else:
byte_range = "Range: bytes=%s-%s\r\n" %(str(start_byte), str(end_byte))
header = "%s %s HTTP/1.1\r\nHost: %s\r\n" %(req_type, path, host)
header += (byte_range + "\r\n")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest creating a dictionary<header-key, header-value> and using that instead. Building a raw string like this is inelegant.

@@ -0,0 +1,162 @@
import argparse
import urlparse
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cant use this module. Use re instead.

"GET",
self.start_byte,
self.end_byte
)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is strange. Prefer:

data_request = request(
  self.path,
  ...
)

import os


def request(path, host, req_type, start_byte, end_byte):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name is inaccurate. "get_headers" is more correct, since you're not actually making any requests.

thread_num+=1
self.threads.append(thread)
for thread in self.threads:
thread.start()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not start in the previous loop?

outfile = os.path.basename(os.path.basename(self.path))
output_file = open(outfile, 'w')
logging.info("Writing To File ...")
s = ""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s is a bad name.

logging.info("Writing To File ...")
s = ""
for num in range(thread_num):
filename = 'tempfile'+str(num)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't you import the tempfile module? Why not use that?

response_data = response_data[first_index + 16 : ]
last_index = response_data.find("\r\n")
response_data = response_data[ : last_index]
response_data.strip()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last few lines look very fragile.

logging.info("Download Completed Successfully !!!")


if __name__ == '__main__' :
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this in a separate file. In order to make your code reuseable, you need to separate core logic from CLI, so that someone can use the download, without having to deal with overhead of CLI.

@sciencepal sciencepal closed this May 14, 2017
@sciencepal sciencepal mentioned this pull request May 15, 2017
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

Successfully merging this pull request may close these issues.

2 participants