Skip to content

Instantly share code, notes, and snippets.

@starlightme
Forked from abrasumente233/nesign.py
Created November 1, 2015 03:17
Show Gist options
  • Save starlightme/3779f68a89b1d3630a88 to your computer and use it in GitHub Desktop.
Save starlightme/3779f68a89b1d3630a88 to your computer and use it in GitHub Desktop.
网易云音乐签到(pc android)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import logging
import requests
'''
A module for helping you to finish the daily task on Neteasy Music
'''
__author__ = 'abrasumente'
TYPE_WEBPC = 1
TYPE_ANDROID = 0
# 关闭 urllib3 的 logging
urllib3_logger = logging.getLogger('urllib3')
urllib3_logger.setLevel(logging.ERROR)
def _config_log(echo, filename=None):
if echo:
if filename:
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(message)s',
datefmt='[%Y-%m-%d %H:%M:%S]',
filename=filename,
filemode='w')
else:
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(message)s',
datefmt='[%Y-%m-%d %H:%M:%S]')
def log_from_code(response_json, platform, name):
code = response_json['code']
if code == -2:
logging.info('{}: {} 失败. 今天签到过了.'.format(name, platform))
elif code == 200:
logging.info('{}: {} ok. 经验 +{}'.format(name, platform, response_json['point']))
else:
logging.info('{}: {} 失败. {}({})'.format(name, platform, code, response_json['msg']))
def nesign(music_u, log=True, log_filename=None, display_name='anonymous'):
_config_log(log, log_filename)
cookies = {'MUSIC_U': music_u}
headers = {'Referer': 'http://music.163.com/'}
result = {}
# web 和 pc 客户端
url = 'http://music.163.com/api/point/dailyTask?csrf_token=placeholder&type={}'.format(TYPE_WEBPC)
response = requests.post(url, cookies=cookies,
headers=headers)
wjson = response.json()
log_from_code(wjson, 'web & pc', display_name)
result['webpc'] = wjson
# web 和 pc 客户端结束
# android
url = 'http://music.163.com/api/point/dailyTask?csrf_token=placeholder&type={}'.format(TYPE_ANDROID)
response = requests.post(url, cookies=cookies,
headers=headers)
ajson = response.json()
log_from_code(ajson, 'android', display_name)
result['android'] = ajson
# android 结束
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment