Skip to content

Instantly share code, notes, and snippets.

@junbaor
Last active June 1, 2020 10:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save junbaor/2d5fbfb3d88dec4fe06b916adaf19639 to your computer and use it in GitHub Desktop.
Save junbaor/2d5fbfb3d88dec4fe06b916adaf19639 to your computer and use it in GitHub Desktop.
即刻-特别关注
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import platform
import sys
import threading
import requests
from telegram import Bot, InlineKeyboardMarkup, InlineKeyboardButton
from telegram.utils.request import Request
reload(sys)
sys.setdefaultencoding('utf-8')
# telegram 机器人的 token, 比如 162114703:AAF6agc82o098RFie06tKTf0bxv-293842
telegram_bot_token = ''
# 私人频道的ID,比如 -1001496422481
chat_id = ''
interval = 3 * 60
# 存放上一次的动态ID, user_id, user_name
new_id_dict = {}
# 关注的人
task_user_info = [
{'user_name': '瓦恁', 'user_id': '82D23B32-CF36-4C59-AD6F-D05E3552CBF3'}
]
def send_notice_msg(user_id, user_name):
reply_markup = InlineKeyboardMarkup([[
InlineKeyboardButton('打开主页', url="https://m.okjike.com/users/" + user_id),
]])
bot.send_message(chat_id=chat_id, text=user_name + "又发即刻动态了,快去看看吧~", reply_markup=reply_markup)
def diff_timer():
try:
for item in task_user_info:
task_user_id = item['user_id']
task_user_name = item['user_name']
old_id = new_id_dict[task_user_id]
new_id = get_new_id(task_user_id)
print "%s | %s | old_id:%s | new_id:%s" % (task_user_id, task_user_name, old_id, new_id)
if old_id != new_id:
print '检测到' + task_user_name + '新动态'
send_notice_msg(task_user_id, task_user_name)
new_id_dict[task_user_id] = new_id
finally:
timer = threading.Timer(interval, diff_timer)
timer.start()
def get_new_id(item_user_id):
headers = {
'Origin': 'https://web.okjike.com',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',
'Content-Type': 'application/json',
'Accept': 'application/json',
'Referer': 'https://web.okjike.com/user/%s/post' % item_user_id,
'platform': 'web',
'x-jike-access-token': '',
'App-Version': '5.3.0',
}
data = '{"loadMoreKey":{},"username":\"%s\","limit":20}' % item_user_id
try:
response = requests.post('https://app.jike.ruguoapp.com/1.0/personalUpdate/single', headers=headers, data=data)
code = response.status_code
if code == 200:
json = response.json()
new_id = json['data'][0]['id']
return new_id
except:
return ''
def init_telegram_bot():
global interval, bot
request_kwargs = {}
# 不等于 Linux 系统说明是本地开发调试, 需要上代理
if platform.system() != 'Linux':
request_kwargs = {'proxy_url': 'http://127.0.0.1:7890'}
interval = 5
bot = Bot(token=telegram_bot_token, request=Request(**request_kwargs))
def init_jike_feed_id():
for user in task_user_info:
task_user_id = user['user_id']
task_user_name = user['user_name']
new_id = get_new_id(task_user_id)
print "init " + task_user_name + " -> " + new_id
new_id_dict[task_user_id] = new_id
if __name__ == '__main__':
init_telegram_bot()
init_jike_feed_id()
diff_timer()
@junbaor
Copy link
Author

junbaor commented May 4, 2019

功能

发现新动态后发送消息到 telegram 频道。

安装依赖:

pip install python-telegram-bot request

需要自行替换 telegram_bot_token ,chat_id ,task_user_info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment