chaojiying.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # coding:utf-8
  2. from hashlib import md5
  3. import requests
  4. class ChaoJiYIngClient:
  5. def __init__(self, username, password, soft_id):
  6. self.username = username
  7. password = password.encode('utf8')
  8. self.password = md5(password).hexdigest()
  9. self.soft_id = soft_id
  10. self.base_params = {
  11. 'user': self.username,
  12. 'pass2': self.password,
  13. 'softid': self.soft_id,
  14. }
  15. self.headers = {
  16. 'Connection': 'Keep-Alive',
  17. 'User-Agent': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
  18. }
  19. def postpic(self, im, codetype):
  20. """
  21. im: 图片字节
  22. codetype: 题目类型 参考 http://www.chaojiying.com/price.html
  23. """
  24. params = {
  25. 'codetype': codetype,
  26. }
  27. params.update(self.base_params)
  28. files = {'userfile': ('ccc.jpg', im)}
  29. r = requests.post('http://upload.chaojiying.net/Upload/Processing.php',
  30. data=params, files=files, headers=self.headers,
  31. timeout=60)
  32. return r.json()
  33. def postpic_base64(self, base64_str, codetype):
  34. """
  35. im: 图片字节
  36. codetype: 题目类型 参考 http://www.chaojiying.com/price.html
  37. """
  38. params = {
  39. 'codetype': codetype,
  40. 'file_base64': base64_str
  41. }
  42. params.update(self.base_params)
  43. r = requests.post('http://upload.chaojiying.net/Upload/Processing.php',
  44. data=params, headers=self.headers, timeout=60)
  45. return r.json()
  46. def report_error(self, im_id):
  47. """
  48. im_id:报错题目的图片ID
  49. """
  50. params = {
  51. 'id': im_id,
  52. }
  53. params.update(self.base_params)
  54. r = requests.post('http://upload.chaojiying.net/Upload/ReportError.php',
  55. data=params, headers=self.headers, timeout=60)
  56. return r.json()
  57. CJ = ChaoJiYIngClient('ddddjy', 'T95jJcRu57sFAFn', '929622')