Tsukasa007 / my_script

學習自動化
Apache License 2.0
346 stars 163 forks source link

什么值得买的cookie需要拿到那些东西 #7

Open SouthWindLoki opened 3 years ago

Tsukasa007 commented 3 years ago

浏览器登录 找cookie就行,样子是这样的 image

loveme1573 commented 3 years ago

云函数怎么部署什么值得买

古斯兰古柯基斯库奇斯库奇,使之成为"不光彩"的"大人" image

请问云函数怎么部署什么值得买脚本

happysoul commented 3 years ago

@Tsukasa007 smzdm_mission.js 40行代码有问题 } else if (process.env.JD_COOKIE.indexOf('\n') > -1) { 应该是 SMZDM_COOKIE

Tsukasa007 commented 3 years ago

好的 改好了

happysoul commented 3 years ago

改的真快 牛 顺便放一个 py自动配置环境并运行的代码,同样其他脚本只需要替换ck和文件下载地址就可以复用 脚本会安装常用node依赖配置环境,win下也可以使用

# -- coding: utf-8 --
import time
import platform
import os
import traceback
import urllib
import urllib.request

osname = platform.system()
print("OS:" + str(osname))

# 需要你的运行环境中有python3.x 同时安装了node环境,也就是执行 node -V 可以看到版本号 建议10+
# 其他推送方式参考 sendNotify.js 变量进行配置,并修改最后的执行传参

# bark
BARK_PUSH=""
# bark 默认静音
BARK_SOUND="silence"

# cookie放这里,多个cookie逗号分隔如 'cookie1','cookie2'
cks = [
    ''
]

url_sendNotify = "https://ghproxy.com/https://raw.githubusercontent.com/Tsukasa007/my_script/master/sendNotify.js"
url_js = "https://ghproxy.com/https://raw.githubusercontent.com/Tsukasa007/my_script/master/smzdm_mission.js"
filename = "smzdm_mission.js"

# 下载文件
def download(url,fname):
    try:
        urllib.request.urlretrieve(url, filename=fname)
        print('文件下载完成')
    except Exception as e:
        print("下载文件失败:")
        print(e)
        traceback.print_exc()

# 修改文件中的字符串
def modify(file,old_str,new_str):
  """
  替换文件中的字符串
  :param file:文件名
  :param old_str:就字符串
  :param new_str:新字符串
  :return:
  """
  file_data = ""
  with open(file, "r", encoding="utf-8") as f:
    for line in f:
      if old_str in line:
        line = line.replace(old_str,new_str)
      file_data += line
  with open(file,"w",encoding="utf-8") as f:
    f.write(file_data)

# js文件是否是今天创建的,每天下载一次最新的代码
def isToday():
    mtime = os.stat(filename).st_mtime
    dt = time.strftime('%Y-%m-%d', time.localtime(mtime))
    nt = time.strftime('%Y-%m-%d', time.localtime())
    return dt == nt

if __name__ == "__main__":

    print("查询node版本号")
    re = os.system("node -v")
    if re!=0:
        print("环境中没有找到node")
        exit(0)

    print("查询yarn版本号")
    re = os.system("yarn -v")
    if re!=0:
        print("环境中没有找到yarn,尝试安装")
        os.system('npm install -g yarn --registry=https://registry.npm.taobao.org')

    sendFile = "sendNotify.js"
    if not os.path.exists('./'+sendFile):
        print("没有找到推送文件:",sendFile)
        download(url_sendNotify,sendFile)
        # 替换追加的推送内容为空
        modify(sendFile, "'\\n\\n仅供用于学习'", "''")

    if not os.path.exists('./package.json'):
        re = os.system("yarn -v")
        if re != 0:
            print('yarn异常,退出')
            exit(0)
        print('配置yarn环境')
        os.system("yarn")
        os.system("yarn add fs")
        os.system("yarn add got")
        os.system("yarn add querystring")

    # 文件不存在或者是昨天的文件则重新下载
    if not os.path.exists(filename) or not isToday():
        download(url_js,filename)

    # 根据运行环境判断是window还是linux使用不同的环境变量
    ex = 'set' if str(osname)=='Windows' else 'export'

    shells = [
        # 如果使用其他的 如 server酱 需要传递参数为 PUSH_KEY
        # "{} PUSH_KEY={}".format(ex,"server酱的发送参数"),
        "{} BARK_PUSH={}".format(ex,BARK_PUSH),
        "{} BARK_SOUND={}".format(ex,BARK_SOUND),
        '{} SMZDM_COOKIE="{}"'.format(ex,'&'.join(cks)),
        "node {}".format(filename)
    ]
    os.system(" && ".join(shells))

    pass