Skip to content

Commit

Permalink
bugfix: js export
Browse files Browse the repository at this point in the history
  • Loading branch information
nenekodev committed Mar 10, 2022
1 parent 78be96b commit dc8d89d
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 158 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ If you don't want to see this warning, you can set it up as a single run by usin

https://github.com/nenekodev/asoul-wecom-notifier/blob/master/.github/workflows/A-SOUL_BOT-RunOnce.yml

- UPDATE: cron schedule **may not start on time.** A solution here: [zh-SC] https://zhuanlan.zhihu.com/p/379365305
- UPDATE: cron schedule **may not start on time.** A solution here: [zh-SC] https://zhuanlan.zhihu.com/p/379365305 or you can try my another project: [Github-Actions-Trigger](https://github.com/nenekodev/Github-Actions-Trigger)


## Configurations
Expand Down
2 changes: 1 addition & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ https://github.com/nenekodev/asoul-wecom-notifier/blob/master/.github/workflows/

https://github.com/nenekodev/asoul-wecom-notifier/blob/master/.github/workflows/A-SOUL_BOT-RunOnce.yml

- 注意:Github Action 自带之 cron schedule 功能**恐不能准时启动**。 你可以参照这篇文章来解决:https://zhuanlan.zhihu.com/p/379365305
- 注意:Github Action 自带之 cron schedule 功能**恐不能准时启动**。 你可以参照这篇文章来解决:https://zhuanlan.zhihu.com/p/379365305 或试试我的另一个项目:[Github-Actions-Trigger](https://github.com/nenekodev/Github-Actions-Trigger)

## 配置

Expand Down
157 changes: 2 additions & 155 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { FormData } from 'formdata-node';
import { formatDate, stripHtml, convertWeiboUrl } from './utils.js';

import { fetchBiliBio, fetchBiliBlog } from './plugins/Bili.js';
import { fetchDouyinLive, fetchDouyin, dyExtract } from './plugins/Douyin.js';
import { fetchDouyinLive, fetchDouyin } from './plugins/Douyin.js';

const argv = yargs(hideBin(process.argv))
.command('run', 'Extract new posts from services', {
Expand Down Expand Up @@ -144,160 +144,7 @@ async function main(config) {
await fetchDouyin(account, config, dbScope, wecomBody);

// //Fetch Weibo
// const weiboRequestOptions = {...config.pluginOptions?.requestOptions, ...headerOnDemand(config.pluginOptions.customCookies.weibo)};

// account.weiboId && await got(`https://m.weibo.cn/profile/info?uid=${account.weiboId}`, weiboRequestOptions).then(async resp => {
// const json = JSON.parse(resp.body);

// if (json?.ok === 1) {
// const currentTime = Date.now();
// const data = json.data;
// const user = data?.user;
// const statuses = data?.statuses;

// if (statuses.length !== 0) {
// // Exclude sticky status when: it is sticky and is older than the first [1] status
// const status = (
// statuses[0]?.isTop === 1 &&
// statuses[0]?.created_at &&
// statuses[1]?.created_at &&
// +new Date(statuses[0].created_at) < +new Date(statuses[1].created_at)
// ) ? statuses[1] : statuses[0];
// const retweeted_status = status?.retweeted_status;

// const timestamp = +new Date(status.created_at);
// const id = status.bid;
// const visibility = status?.visible?.type;
// const editCount = status?.edit_count || 0;
// let text = status?.raw_text || stripHtml(status.text);

// if (status?.isLongText) {
// log('weibo got post too long, trying extended text...')
// await got(`https://m.weibo.cn/statuses/extend?id=${id}`, weiboRequestOptions).then(async resp => {
// const json = JSON.parse(resp.body);

// if (json?.ok === 1 && json?.data?.longTextContent) {
// text = stripHtml(json.data.longTextContent);
// } else {
// log('weibo extended info corrupted, using original text...');
// }
// });
// }


// argv.json && fs.writeFile(`db/${account.slug}-weibo.json`, JSON.stringify(json, null, 2), err => {
// if (err) return console.log(err);
// });

// const visibilityMap = {
// 1: `自己可见`,
// 6: `好友圈可见`,
// 10: `粉丝可见`
// }

// const dbStore = {
// scrapedTime: new Date(currentTime),
// scrapedTimeUnix: +new Date(currentTime),
// user: user,
// latestStatus: {
// id: id,
// text: text,
// visibility: visibility,
// editCount: editCount,
// timestamp: new Date(timestamp),
// timestampUnix: timestamp,
// timeAgo: timeAgo(timestamp),
// }
// };

// let readyToSend = 0;

// // If user nickname update
// if (user.screen_name !== dbScope?.weibo?.user?.screen_name && dbScope?.weibo?.user?.screen_name) {
// log(`weibo user nickname updated: ${user.screen_name}`);

// wecomBody.textcard.title = `${msgPrefix}· 微博昵称更新`;
// wecomBody.textcard.description = `新:${user.screen_name}\n旧:${dbScope?.weibo?.user?.screen_name}`;
// wecomBody.textcard.url = `https://weibo.com/${user.id}`;

// readyToSend = 1;
// }

// // If user description update
// if (user.description !== dbScope?.weibo?.user?.description && dbScope?.weibo?.user?.description) {
// log(`weibo user sign updated: ${user.description}`);

// wecomBody.textcard.title = `${msgPrefix}· 微博签名更新`;
// wecomBody.textcard.description = `新:${user.description}\n旧:${dbScope?.weibo?.user?.description}`;
// wecomBody.textcard.url = `https://weibo.com/${user.id}`;

// readyToSend = 1;
// }

// // If user avatar update
// if (user.avatar_hd !== dbScope?.weibo?.user?.avatar_hd && dbScope?.weibo?.user?.avatar_hd) {
// log(`weibo user avatar updated: ${user.avatar_hd}`);

// wecomBody.textcard.title = `${msgPrefix}· 微博头像更新`;
// wecomBody.textcard.description = `旧:${dbScope?.weibo?.user?.avatar_hd}\n点击卡片查看`;
// wecomBody.textcard.url = `${dbScope?.weibo?.user?.avatar_hd}`;

// readyToSend = 1;
// }

// // If user cover background update
// if (user.cover_image_phone !== dbScope?.weibo?.user?.cover_image_phone && dbScope?.weibo?.user?.cover_image_phone) {
// log(`weibo user cover updated: ${user.cover_image_phone}`);

// wecomBody.textcard.title = `${msgPrefix}· 微博封面更新`;
// wecomBody.textcard.description = `旧:${dbScope?.weibo?.user?.cover_image_phone}\n点击卡片查看`;
// wecomBody.textcard.url = `${dbScope?.weibo?.user?.cover_image_phone}`;

// readyToSend = 1;
// }

// // If latest post is newer than the one in database
// if (id !== dbScope?.weibo?.latestStatus?.id && timestamp > dbScope?.weibo?.latestStatus?.timestampUnix) {
// log(`weibo got update: ${id} (${timeAgo(timestamp)})`);

// wecomBody.textcard.title = `${msgPrefix}· 发布微博动态`;
// wecomBody.textcard.description = `${visibilityMap[visibility] || ''}${retweeted_status ? `转发` : `动态`}:${text}${retweeted_status ? `\n\n@${retweeted_status.user.screen_name}:${stripHtml(retweeted_status.text)}` : ''}`;
// wecomBody.textcard.url = `https://weibo.com/${user.id}/${id}`;

// if ((currentTime - timestamp) >= config.weiboBotThrottle) {
// log(`weibo too old, notifications skipped`);
// } else {
// readyToSend = 1;
// }
// } else if (id !== dbScope?.weibo?.latestStatus?.id && timestamp < dbScope?.weibo?.latestStatus?.timestampUnix) {
// log(`weibo new post older than database. latest: ${id} (${timeAgo(timestamp)})`);

// } else {
// log(`weibo no update. latest: ${id} (${timeAgo(timestamp)})`);
// }

// if (readyToSend === 1) {
// await sendWecom({}, wecomBody)
// .then(resp => {
// readyToSend = 0;
// })
// .catch(err => {
// log(`Wecom post error: ${err?.response?.body || err}`);
// });
// }

// // Set new data to database
// dbScope['weibo'] = dbStore;
// } else {
// log('weibo empty result, skipping...');
// }
// } else {
// log('weibo info corrupted, skipping...');
// }
// })
// .catch(err => {
// log(`weibo request error: ${err}`);
// });
//


// Write new data to database
Expand Down
154 changes: 154 additions & 0 deletions plugins/Weibo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
const weiboRequestOptions = {...config.pluginOptions?.requestOptions, ...headerOnDemand(config.pluginOptions.customCookies.weibo)};

// account.weiboId && await got(`https://m.weibo.cn/profile/info?uid=${account.weiboId}`, weiboRequestOptions).then(async resp => {
// const json = JSON.parse(resp.body);

// if (json?.ok === 1) {
// const currentTime = Date.now();
// const data = json.data;
// const user = data?.user;
// const statuses = data?.statuses;

// if (statuses.length !== 0) {
// // Exclude sticky status when: it is sticky and is older than the first [1] status
// const status = (
// statuses[0]?.isTop === 1 &&
// statuses[0]?.created_at &&
// statuses[1]?.created_at &&
// +new Date(statuses[0].created_at) < +new Date(statuses[1].created_at)
// ) ? statuses[1] : statuses[0];
// const retweeted_status = status?.retweeted_status;

// const timestamp = +new Date(status.created_at);
// const id = status.bid;
// const visibility = status?.visible?.type;
// const editCount = status?.edit_count || 0;
// let text = status?.raw_text || stripHtml(status.text);

// if (status?.isLongText) {
// log('weibo got post too long, trying extended text...')
// await got(`https://m.weibo.cn/statuses/extend?id=${id}`, weiboRequestOptions).then(async resp => {
// const json = JSON.parse(resp.body);

// if (json?.ok === 1 && json?.data?.longTextContent) {
// text = stripHtml(json.data.longTextContent);
// } else {
// log('weibo extended info corrupted, using original text...');
// }
// });
// }


// argv.json && fs.writeFile(`db/${account.slug}-weibo.json`, JSON.stringify(json, null, 2), err => {
// if (err) return console.log(err);
// });

// const visibilityMap = {
// 1: `自己可见`,
// 6: `好友圈可见`,
// 10: `粉丝可见`
// }

// const dbStore = {
// scrapedTime: new Date(currentTime),
// scrapedTimeUnix: +new Date(currentTime),
// user: user,
// latestStatus: {
// id: id,
// text: text,
// visibility: visibility,
// editCount: editCount,
// timestamp: new Date(timestamp),
// timestampUnix: timestamp,
// timeAgo: timeAgo(timestamp),
// }
// };

// let readyToSend = 0;

// // If user nickname update
// if (user.screen_name !== dbScope?.weibo?.user?.screen_name && dbScope?.weibo?.user?.screen_name) {
// log(`weibo user nickname updated: ${user.screen_name}`);

// wecomBody.textcard.title = `${msgPrefix}· 微博昵称更新`;
// wecomBody.textcard.description = `新:${user.screen_name}\n旧:${dbScope?.weibo?.user?.screen_name}`;
// wecomBody.textcard.url = `https://weibo.com/${user.id}`;

// readyToSend = 1;
// }

// // If user description update
// if (user.description !== dbScope?.weibo?.user?.description && dbScope?.weibo?.user?.description) {
// log(`weibo user sign updated: ${user.description}`);

// wecomBody.textcard.title = `${msgPrefix}· 微博签名更新`;
// wecomBody.textcard.description = `新:${user.description}\n旧:${dbScope?.weibo?.user?.description}`;
// wecomBody.textcard.url = `https://weibo.com/${user.id}`;

// readyToSend = 1;
// }

// // If user avatar update
// if (user.avatar_hd !== dbScope?.weibo?.user?.avatar_hd && dbScope?.weibo?.user?.avatar_hd) {
// log(`weibo user avatar updated: ${user.avatar_hd}`);

// wecomBody.textcard.title = `${msgPrefix}· 微博头像更新`;
// wecomBody.textcard.description = `旧:${dbScope?.weibo?.user?.avatar_hd}\n点击卡片查看`;
// wecomBody.textcard.url = `${dbScope?.weibo?.user?.avatar_hd}`;

// readyToSend = 1;
// }

// // If user cover background update
// if (user.cover_image_phone !== dbScope?.weibo?.user?.cover_image_phone && dbScope?.weibo?.user?.cover_image_phone) {
// log(`weibo user cover updated: ${user.cover_image_phone}`);

// wecomBody.textcard.title = `${msgPrefix}· 微博封面更新`;
// wecomBody.textcard.description = `旧:${dbScope?.weibo?.user?.cover_image_phone}\n点击卡片查看`;
// wecomBody.textcard.url = `${dbScope?.weibo?.user?.cover_image_phone}`;

// readyToSend = 1;
// }

// // If latest post is newer than the one in database
// if (id !== dbScope?.weibo?.latestStatus?.id && timestamp > dbScope?.weibo?.latestStatus?.timestampUnix) {
// log(`weibo got update: ${id} (${timeAgo(timestamp)})`);

// wecomBody.textcard.title = `${msgPrefix}· 发布微博动态`;
// wecomBody.textcard.description = `${visibilityMap[visibility] || ''}${retweeted_status ? `转发` : `动态`}:${text}${retweeted_status ? `\n\n@${retweeted_status.user.screen_name}:${stripHtml(retweeted_status.text)}` : ''}`;
// wecomBody.textcard.url = `https://weibo.com/${user.id}/${id}`;

// if ((currentTime - timestamp) >= config.weiboBotThrottle) {
// log(`weibo too old, notifications skipped`);
// } else {
// readyToSend = 1;
// }
// } else if (id !== dbScope?.weibo?.latestStatus?.id && timestamp < dbScope?.weibo?.latestStatus?.timestampUnix) {
// log(`weibo new post older than database. latest: ${id} (${timeAgo(timestamp)})`);

// } else {
// log(`weibo no update. latest: ${id} (${timeAgo(timestamp)})`);
// }

// if (readyToSend === 1) {
// await sendWecom({}, wecomBody)
// .then(resp => {
// readyToSend = 0;
// })
// .catch(err => {
// log(`Wecom post error: ${err?.response?.body || err}`);
// });
// }

// // Set new data to database
// dbScope['weibo'] = dbStore;
// } else {
// log('weibo empty result, skipping...');
// }
// } else {
// log('weibo info corrupted, skipping...');
// }
// })
// .catch(err => {
// log(`weibo request error: ${err}`);
// });
1 change: 0 additions & 1 deletion utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import chalk from 'chalk';

import { formatDistanceToNowStrict } from 'date-fns';

export function timeAgo(timestamp, suffix = true) {
Expand Down

0 comments on commit dc8d89d

Please sign in to comment.