├── .github └── workflows │ └── main.yml ├── .gitignore ├── README.md ├── img ├── add_BDUSS.png ├── check.png ├── edit.png ├── new_repository_secret.png └── update.png └── main.py /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: 'Baidu Tieba Auto Sign' 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | schedule: 8 | - cron: '5 16,22 * * *' 9 | 10 | jobs: 11 | tieba_sign: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: 'Checkout codes' 15 | uses: actions/checkout@v2 16 | - name: 'Set python' 17 | uses: actions/setup-python@v1 18 | with: 19 | python-version: '3.6' 20 | - name: 'Install dependencies' 21 | run: python -m pip install --upgrade requests 22 | - name: 'Start Sign' 23 | env: 24 | BDUSS: ${{ secrets.BDUSS }} 25 | HOST: ${{ secrets.HOST }} 26 | FROM: ${{ secrets.FROM }} 27 | TO: ${{ secrets.TO }} 28 | AUTH: ${{ secrets.AUTH }} 29 | run: python main.py 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 贴吧签到Github Action版 2 | 3 | ## 今日签到状态 4 | 5 |  6 | 7 | ## 使用说明 8 | 9 | 1. Fork 本仓库,然后点击你的仓库右上角的 Settings,找到 Secrets 这一项,添加一个库秘密变量。其中 `BDUSS` 存放你的 BDUSS。支持同时添加多个帐户,BDUSS 之间用 `#` 隔开即可。 10 | 11 | 2. 设置好环境变量后点击你的仓库上方的 `Actions` 选项,第一次打开需要点击 `I understand...` 按钮,确认在 Fork 的仓库上启用 GitHub Actions 。 12 | 13 | 3. 任意发起一次commit,可以参考下图流程修改readme文件。 14 | 15 | - 打开`README.md`,点击修改按钮 16 | - 修改任意内容,这里在末尾插入了空格。移动到最下面,点击提交。 17 | 18 | 4. 至此自动签到就搭建完毕了,可以再次点击`Actions`查看工作记录,如果有`Baidu Tieba Auto Sign`则说明workflow创建成功了。点击右侧记录可以查看详细签到情况。 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /img/add_BDUSS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gwtak/TieBaSign/ee6f53e8726d067336e92c7f8f539b487b02b4bf/img/add_BDUSS.png -------------------------------------------------------------------------------- /img/check.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gwtak/TieBaSign/ee6f53e8726d067336e92c7f8f539b487b02b4bf/img/check.png -------------------------------------------------------------------------------- /img/edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gwtak/TieBaSign/ee6f53e8726d067336e92c7f8f539b487b02b4bf/img/edit.png -------------------------------------------------------------------------------- /img/new_repository_secret.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gwtak/TieBaSign/ee6f53e8726d067336e92c7f8f539b487b02b4bf/img/new_repository_secret.png -------------------------------------------------------------------------------- /img/update.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gwtak/TieBaSign/ee6f53e8726d067336e92c7f8f539b487b02b4bf/img/update.png -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | import os 3 | import requests 4 | import hashlib 5 | import time 6 | import copy 7 | import logging 8 | import random 9 | 10 | import smtplib 11 | from email.mime.text import MIMEText 12 | 13 | 14 | logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') 15 | logger = logging.getLogger(__name__) 16 | 17 | # API_URL 18 | LIKIE_URL = "http://c.tieba.baidu.com/c/f/forum/like" 19 | TBS_URL = "http://tieba.baidu.com/dc/common/tbs" 20 | SIGN_URL = "http://c.tieba.baidu.com/c/c/forum/sign" 21 | 22 | ENV = os.environ 23 | 24 | HEADERS = { 25 | 'Host': 'tieba.baidu.com', 26 | 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36', 27 | } 28 | SIGN_DATA = { 29 | '_client_type': '2', 30 | '_client_version': '9.7.8.0', 31 | '_phone_imei': '000000000000000', 32 | 'model': 'MI+5', 33 | "net_type": "1", 34 | } 35 | 36 | # VARIABLE NAME 37 | COOKIE = "Cookie" 38 | BDUSS = "BDUSS" 39 | EQUAL = r'=' 40 | EMPTY_STR = r'' 41 | TBS = 'tbs' 42 | PAGE_NO = 'page_no' 43 | ONE = '1' 44 | TIMESTAMP = "timestamp" 45 | DATA = 'data' 46 | FID = 'fid' 47 | SIGN_KEY = 'tiebaclient!!!' 48 | UTF8 = "utf-8" 49 | SIGN = "sign" 50 | KW = "kw" 51 | 52 | s = requests.Session() 53 | 54 | 55 | def get_tbs(bduss): 56 | logger.info("获取tbs开始") 57 | headers = copy.copy(HEADERS) 58 | headers.update({COOKIE: EMPTY_STR.join([BDUSS, EQUAL, bduss])}) 59 | try: 60 | tbs = s.get(url=TBS_URL, headers=headers, timeout=5).json()[TBS] 61 | except Exception as e: 62 | logger.error("获取tbs出错" + e) 63 | logger.info("重新获取tbs开始") 64 | tbs = s.get(url=TBS_URL, headers=headers, timeout=5).json()[TBS] 65 | logger.info("获取tbs结束") 66 | return tbs 67 | 68 | 69 | def get_favorite(bduss): 70 | logger.info("获取关注的贴吧开始") 71 | # 客户端关注的贴吧 72 | returnData = {} 73 | i = 1 74 | data = { 75 | 'BDUSS': bduss, 76 | '_client_type': '2', 77 | '_client_id': 'wappc_1534235498291_488', 78 | '_client_version': '9.7.8.0', 79 | '_phone_imei': '000000000000000', 80 | 'from': '1008621y', 81 | 'page_no': '1', 82 | 'page_size': '200', 83 | 'model': 'MI+5', 84 | 'net_type': '1', 85 | 'timestamp': str(int(time.time())), 86 | 'vcode_tag': '11', 87 | } 88 | data = encodeData(data) 89 | try: 90 | res = s.post(url=LIKIE_URL, data=data, timeout=5).json() 91 | except Exception as e: 92 | logger.error("获取关注的贴吧出错" + e) 93 | return [] 94 | returnData = res 95 | if 'forum_list' not in returnData: 96 | returnData['forum_list'] = [] 97 | if res['forum_list'] == []: 98 | return {'gconforum': [], 'non-gconforum': []} 99 | if 'non-gconforum' not in returnData['forum_list']: 100 | returnData['forum_list']['non-gconforum'] = [] 101 | if 'gconforum' not in returnData['forum_list']: 102 | returnData['forum_list']['gconforum'] = [] 103 | while 'has_more' in res and res['has_more'] == '1': 104 | i = i + 1 105 | data = { 106 | 'BDUSS': bduss, 107 | '_client_type': '2', 108 | '_client_id': 'wappc_1534235498291_488', 109 | '_client_version': '9.7.8.0', 110 | '_phone_imei': '000000000000000', 111 | 'from': '1008621y', 112 | 'page_no': str(i), 113 | 'page_size': '200', 114 | 'model': 'MI+5', 115 | 'net_type': '1', 116 | 'timestamp': str(int(time.time())), 117 | 'vcode_tag': '11', 118 | } 119 | data = encodeData(data) 120 | try: 121 | res = s.post(url=LIKIE_URL, data=data, timeout=5).json() 122 | except Exception as e: 123 | logger.error("获取关注的贴吧出错" + e) 124 | continue 125 | if 'forum_list' not in res: 126 | continue 127 | if 'non-gconforum' in res['forum_list']: 128 | returnData['forum_list']['non-gconforum'].append(res['forum_list']['non-gconforum']) 129 | if 'gconforum' in res['forum_list']: 130 | returnData['forum_list']['gconforum'].append(res['forum_list']['gconforum']) 131 | 132 | t = [] 133 | for i in returnData['forum_list']['non-gconforum']: 134 | if isinstance(i, list): 135 | for j in i: 136 | if isinstance(j, list): 137 | for k in j: 138 | t.append(k) 139 | else: 140 | t.append(j) 141 | else: 142 | t.append(i) 143 | for i in returnData['forum_list']['gconforum']: 144 | if isinstance(i, list): 145 | for j in i: 146 | if isinstance(j, list): 147 | for k in j: 148 | t.append(k) 149 | else: 150 | t.append(j) 151 | else: 152 | t.append(i) 153 | logger.info("获取关注的贴吧结束") 154 | return t 155 | 156 | 157 | def encodeData(data): 158 | s = EMPTY_STR 159 | keys = data.keys() 160 | for i in sorted(keys): 161 | s += i + EQUAL + str(data[i]) 162 | sign = hashlib.md5((s + SIGN_KEY).encode(UTF8)).hexdigest().upper() 163 | data.update({SIGN: str(sign)}) 164 | return data 165 | 166 | 167 | def client_sign(bduss, tbs, fid, kw): 168 | # 客户端签到 169 | logger.info("开始签到贴吧:" + kw) 170 | data = copy.copy(SIGN_DATA) 171 | data.update({BDUSS: bduss, FID: fid, KW: kw, TBS: tbs, TIMESTAMP: str(int(time.time()))}) 172 | data = encodeData(data) 173 | res = s.post(url=SIGN_URL, data=data, timeout=5).json() 174 | return res 175 | 176 | def send_email(sign_list): 177 | if ('HOST' not in ENV or 'FROM' not in ENV or 'TO' not in ENV or 'AUTH' not in ENV): 178 | logger.error("未配置邮箱") 179 | return 180 | HOST = ENV['HOST'] 181 | FROM = ENV['FROM'] 182 | TO = ENV['TO'].split('#') 183 | AUTH = ENV['AUTH'] 184 | length = len(sign_list) 185 | subject = f"{time.strftime('%Y-%m-%d', time.localtime())} 签到{length}个贴吧" 186 | body = """ 187 | 197 | """ 198 | for i in sign_list: 199 | body += f""" 200 |