-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathtwitter.mjs
48 lines (42 loc) · 1.25 KB
/
twitter.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import Twit from "twit";
import { formatDate } from "./helpers.mjs";
import entities from "entities";
import { config } from "./config.mjs";
var T = new Twit(config.twitterToken);
const getTweets = async (url) => {
const x = await T.get(`search/tweets`, {
q: url,
count: 20,
tweet_mode: "extended",
result_type: "popular",
});
return x.data.statuses;
};
const getTweetText = (x) => {
const textRaw = entities.decode(x.full_text || x.text);
const text = textRaw
.replace(/(https:\/\/t\.co\S+)/, "")
.trim()
.replace(/\n+/g, "\n - ");
return text;
};
const url = process.argv[2];
console.log("%%tana%%");
getTweets(url)
.then((tweets) => {
tweets.forEach((firstTweet) => {
if (getTweetText(firstTweet).trim() !== "") {
let result = `- ${getTweetText(firstTweet).split("\n").join(" ")} #tweet
- Tweet URL:: https://twitter.com/${firstTweet.user.screen_name}/status/${
firstTweet.id
}
- Name:: [[${firstTweet.user.name}]]
- Twitter username:: [@${firstTweet.user.screen_name}](https://twitter.com/${
firstTweet.user.screen_name
})__
- Date:: [[${formatDate(firstTweet.created_at)}]]`;
console.log(result);
}
});
})
.catch((e) => console.error(e));