Skip to content

fix api change 20170422 #4

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions leetcodeDownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
CHECK_PAGE = 'Check page '
USAGE = "usage: leetcodeDownloader.py username"

SUBMISSION_URL = 'https://leetcode.com/api/submissions/my/'
SUBMISSION_URL = 'https://leetcode.com/api/submissions/?offset='
BASE_URL = 'https://leetcode.com'

def downloadSubmission(session, name, file_type, URL):
Expand All @@ -26,7 +26,12 @@ def downloadSubmission(session, name, file_type, URL):
return
r = session.get(URL)
code = re.search(r'submissionCode\:\ \'([^\']+)\'', r.content).group(1)
code = code.encode('utf8')

# address to possible UnicodeDecodeError for Chinese Characters
reload(sys)
sys.setdefaultencoding('utf8')
Copy link
Owner

Choose a reason for hiding this comment

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

I think it's not a very good way to deal with decode error in Python 2.
The data can be first decoded to unicode and then encode to utf-8 like following code.
code = code.decode('utf-8')
s = json.loads('{"code": "%s"}' % code)
...
f.write(s['code'].encode('utf-8'))


code = code.encode()
s = json.loads('{"code": "%s"}' % code)
print ADD_FILE + filename
f = open(filename, 'w')
Expand Down