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

[itchat] Download multiple files in batch will produce duplicated contents #30

Closed
blueset opened this issue Jul 29, 2018 · 0 comments
Closed

Comments

@blueset
Copy link
Member

blueset commented Jul 29, 2018

Fix: Update code in itchat/components/messages.py

        elif m['MsgType'] == 49: # sharing
            if m['AppMsgType'] == 6:
                rawMsg = m
                cookiesList = {name:data for name,data in core.s.cookies.items()}
                url = core.loginInfo['fileUrl'] + '/webwxgetmedia'
                params = {
                    'sender': rawMsg['FromUserName'],
                    'mediaid': rawMsg['MediaId'],
                    'filename': rawMsg['FileName'],
                    'fromuser': core.loginInfo['wxuin'],
                    'pass_ticket': 'undefined',
                    'webwx_data_ticket': cookiesList['webwx_data_ticket'],}
                headers = { 'User-Agent' : config.USER_AGENT }
                def download_atta(attaDir=None):
                    r = core.s.get(url, params=params, stream=True, headers=headers)
                    tempStorage = io.BytesIO()
                    for block in r.iter_content(1024):
                        tempStorage.write(block)
                    if attaDir is None:
                        return tempStorage.getvalue()
                    with open(attaDir, 'wb') as f:
                        f.write(tempStorage.getvalue())
                    return ReturnValue({'BaseResponse': {
                        'ErrMsg': 'Successfully downloaded',
                        'Ret': 0, }})
                msg = {
                    'Type': 'Attachment',
                    'Text': download_atta, }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant