-
Notifications
You must be signed in to change notification settings - Fork 0
/
tweetOnThisDayPosts.m
77 lines (62 loc) · 2.34 KB
/
tweetOnThisDayPosts.m
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
% Run on 4 hours interval to make tweet the articles
% that were posted during the same time period in the previous years.
% Check tweetOnThisDayPost.yml
% Copyright (c) 2022-2023 Michio Inoue.
% Load the list into timetable (make sure if it was generated)
nYear = year(datetime);
try
data = readtimetable("onThisDayQiita" + nYear + ".csv",'DateLocale','en_US');
catch ME
disp("There is an issue with onThisDayQiita" + nYear + ".csv")
disp("Please run getAllQiitaArticles.m to regenerate the file.")
disp("This program ends here.")
rethrow(ME)
end
disp("onThisDayQiita" + nYear + ".csv is loaded");
data.twitterID = string(data.twitterID);
% Check the item with more than 2 likes and posted in the previous years.
idx2 = data.likes_count > 2 & data.howOld > 0;
data2 = data(idx2,:);
%%
% This script runs on 4 hours interval.
% Extract the articles within the range.
% Shift datetimes back to hour (GitHub Actions does not start at the top of
% the hour. Assume it does not delay more than an hour.
tnow = dateshift(datetime,'start','hour');
t1 = tnow - calyears(year(datetime));
period = 4;
trange = timerange(t1, t1+hours(period));
subdata = data2(trange,:);
if height(subdata) == 0
disp("no qiita during this time frame: " + string(tnow) + " - " + string(tnow + hours(period)));
disp("Completed.")
return;
else
disp(height(subdata) + " items found during this time frame: " + string(tnow) + " - " + string(tnow + hours(period)));
end
% Generate twitter ID to mantion on Twitter
idxTwitterTrue = strlength(subdata.twitterID) > 0;
subdata.twitterID(idxTwitterTrue) = "(@" + subdata.twitterID(idxTwitterTrue) + ")";
% A function to generate a tweet
string2tweet = @(howOld, title, user, url, twitterID) ...
"["+string(howOld)+"年前の投稿] #qiita #matlab #simulink #onthisday" + newline ...
+ title + " by " + user + " さん " + twitterID + newline ...
+ url;
%% Tweet if any with in the time period
tweetFlag = true;
N = height(subdata);
for ii=1:N
str = string2tweet(subdata.howOld(ii), subdata.title{ii}, subdata.user(ii), ...
subdata.url(ii), subdata.twitterID(ii));
% Display Tweet sentense
disp(str);
if tweetFlag
try
disp("Tweeting " + ii + "/" + N + "...");
py.tweetQiita.tweetV2(str)
catch ME
disp(ME)
end
end
end
disp("Completed.")