Skip to content
This repository has been archived by the owner on Nov 28, 2019. It is now read-only.

Commit

Permalink
Merge pull request #25 from serika00/open_vcode
Browse files Browse the repository at this point in the history
  • Loading branch information
sdvcrx committed Nov 20, 2015
2 parents 0e4d69a + f70a2dc commit 1ac3e72
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion bddown_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re
import os
import json
import platform
import pickle
from time import time
try:
Expand All @@ -19,6 +20,7 @@

BAIDUPAN_SERVER = "http://pan.baidu.com/api/"
DLTYPE_MULTIPLE = 'multi_file'
VCODE = 'vcode.jpg'

class Pan(object):
headers = {
Expand Down Expand Up @@ -52,11 +54,18 @@ def _save_img(self, img_url):
"""Download vcode image and save it to path of source code."""
r = self.session.get(img_url)
data = r.content
img_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'vcode.jpg')
img_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), VCODE)
with open(img_path, mode='wb') as fp:
fp.write(data)
print("Saved verification code to ", os.path.dirname(os.path.abspath(__file__)))

def _try_open_img(self, vcode):
_platform = platform.system().lower()
if _platform == 'darwin':
os.system('open ' + vcode)
elif _platform == 'windows':
os.system('start ' + vcode)

def _handle_captcha(self, bdstoken=None):
url = BAIDUPAN_SERVER + 'getcaptcha'
d = {}
Expand All @@ -69,6 +78,7 @@ def _handle_captcha(self, bdstoken=None):
if res.ok:
t = res.json()
self._save_img(t['vcode_img'])
self._try_open_img(os.path.join(os.path.dirname(os.path.abspath(__file__)), VCODE))
vcode_input = raw_input("Please input the captcha:\n")
d['vcode_str'] = t['vcode_str']
d['vcode_input'] = vcode_input
Expand Down

0 comments on commit 1ac3e72

Please sign in to comment.