-
Notifications
You must be signed in to change notification settings - Fork 21
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
Conversation
There was a problem hiding this 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)) |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 | ||
) |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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 = "" |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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__' : |
There was a problem hiding this comment.
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.
Please Review @kaustubh-karkare