-
Notifications
You must be signed in to change notification settings - Fork 92
add --zip option to zip the submission file prior to uploading it #52
base: master
Are you sure you want to change the base?
Changes from 1 commit
b5946c6
7b33aaa
d3c68a4
f0869ee
f8a67f8
5116008
ff4a29a
23bb924
574019d
9158c36
551a1b2
7f9b3c0
bd0cfed
9e5d725
d17fe8c
2bb95b4
1b0ae53
be32ad4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ def get_parser(self, prog_name): | |
parser.add_argument('-u', '--username', help='username') | ||
parser.add_argument('-p', '--password', help='password') | ||
parser.add_argument('-z', '--zip', type=self._str2bool, nargs='?', const=True, default=False, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't you use the same argument setting as i.e. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agree |
||
help='zip the submission file before uploading') | ||
help='whether to zip the submission file before uploading') | ||
|
||
return parser | ||
|
||
|
@@ -35,7 +35,12 @@ def take_action(self, parsed_args): | |
username = config.get('username', '') | ||
password = config.get('password', '') | ||
competition = config.get('competition', '') | ||
zip = config.get('zip', False) | ||
zip_flag = config.get('zip', 'no') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use getboolean method instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @floydwch but the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This issue should be resolved at the config provider level, I'll address it. |
||
|
||
if Submit._str2bool(zip_flag): | ||
zip = True | ||
else: | ||
zip = False | ||
|
||
browser = common.login(username, password) | ||
base = 'https://www.kaggle.com' | ||
|
@@ -46,7 +51,7 @@ def take_action(self, parsed_args): | |
entry = parsed_args.entry | ||
message = parsed_args.message | ||
|
||
archive_name = Submit._rand_str(10)+'.zip' | ||
archive_name = Submit._rand_str(10) + '.zip' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the uploaded file's name will also show on the Kaggle's dashboard. A related name might be better. i.e. append the uuid or timestamp to the original submission file's name. And another concern there is, for myself habit, the submission files are already suffixed a timestamp to distinguish the trial. Adding additional suffix is duplicated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. What if I prepend a short random string instead? |
||
|
||
if zip: | ||
with zipfile.ZipFile(archive_name, 'w', zipfile.ZIP_DEFLATED) as zf: | ||
|
@@ -122,10 +127,11 @@ def take_action(self, parsed_args): | |
@staticmethod | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Static method is not the best choice in such case. And an underscore prefix method indicates this method is private, which means it'll access the object's private fields, but it's not the case here. I suggest you extract the method to the module scope, i.e. move the |
||
def _str2bool(v): | ||
""" | ||
parse boolean values | ||
parse truthy/falsy strings into booleans | ||
|
||
https://stackoverflow.com/a/43357954/436721 | ||
:return: | ||
:param v: the string to be parsed | ||
:return: a boolean value | ||
""" | ||
if v.lower() in ('yes', 'true', 't', 'y', '1'): | ||
return True | ||
|
@@ -136,4 +142,12 @@ def _str2bool(v): | |
|
||
@staticmethod | ||
def _rand_str(length): | ||
return uuid.uuid4().hex[:length-1] | ||
""" | ||
this is used to prevent caching issues | ||
|
||
https://stackoverflow.com/a/34017605/436721 | ||
|
||
:param length: integer length | ||
:return: a random string of the given length | ||
""" | ||
return uuid.uuid4().hex[:length - 1] |
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.
Is it an accident duplicated indent?
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.
IDE issues I guess