Last active
December 14, 2021 12:28
-
-
Save sevenc-nanashi/01a5ed48e1e07244ce17962d350d426f to your computer and use it in GitHub Desktop.
GitHub RSS widget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r = HttpRequest.get("https://github.com/user-name-here.private.atom?token=Y0urT0k3nH3re") | |
exit unless r.success? | |
pattern = <<'EOS'.chomp | |
<entry> | |
<id>tag:github\.com,2008:(?<eventname>.+)/(?<eventid>.+)</id> | |
<published>(?<published>.+)</published> | |
<updated>(?<updated>.+)</updated> | |
<link type="text/html" rel="alternate" href="(?<link>.+)"/> | |
<title type="html">(?<title>.+)</title> | |
<author> | |
<name>(?<author_name>.+)</name> | |
(<email>(?<author_email>.+)</email>)? | |
<uri>(?<author_url>.+)</uri> | |
</author> | |
<media:thumbnail height="30" width="30" url="(?<author_avatar>.+)"/> | |
<content type="html">[\s\S]+?</content> | |
</entry> | |
EOS | |
event_patterns = { | |
"FollowEvent" => [/(.+) started following (.+)+/, '\1 が \2 をフォローしました。'], | |
"WatchEvent" => [/(.+) starred (.+)/, '\1 が \2 をスターしました。'], | |
"CreateEvent" => [/(.+) created a repository (.+)/, '\1 がリポジトリ \2 を作成しました。'], | |
"ForkEvent" => [/(.+) forked (.+) from (.+)/, '\1 が \3 をフォークしました。'], | |
"PublicEvent" => [/(.+) made (.+) public/, '\1 が \2 を公開しました。'], | |
"PushEvent" => [/(.+) pushed to (.+) in (.+)/, '\1 が \3 の \2 にプッシュしました。'], | |
"ReleaseEvent" => [/(.+) released (.+) at (.+)/, '\1 が \3 で \2 をリリースしました。'] | |
} | |
re = Regexp.new(pattern) | |
res = r.body.scan(re) | |
COUNT = 4 | |
DATE = /(\d+)\-(\d+)\-(\d+)T(\d+):(\d+):(\d+)Z/ | |
MONTHS = [ | |
nil, 31, 30, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 | |
] | |
current = Time.new.to_s.sub /\d+-0?(\d+)-(\d+) (\d+):(\d+):(\d+) \+0900/, '\1/\2 \3:\4' | |
mainwidget = WidgetUI.new do | |
VStack { | |
Spacer().frame(width: :infinity, height: 10) | |
HStack { | |
Spacer().frame(width: 10, height: :infinity) | |
VStack(alignment: :center) { | |
res[0, COUNT].each_with_index do |r, i| | |
ep = event_patterns[r[0]] | |
Spacer().frame(width: :infinity, height: 5) | |
VStack { | |
Text(ep == nil ? r[5] : r[5].sub(ep[0], ep[1])).bold.color(Color.hex("ffffff")).size(9) | |
date = r[2].match(DATE) | |
m = date[2].to_i | |
d = date[3].to_i | |
h = date[4].to_i + 9 | |
if h > 24 | |
d += 1 | |
h -= 24 | |
if MONTHS[m] < d | |
d = 1 | |
m += 1 | |
if m > 12 | |
m = 1 | |
end | |
end | |
end | |
Text("#{m}/#{d.to_s.rjust(2, "0")} #{h.to_s.rjust(2, "0")}:#{date[5]}").color(Color.hex("ffffff")).size(7) | |
} | |
if i < COUNT - 1 | |
Spacer().frame(width: :infinity, height: 5) | |
Divider() | |
end | |
end | |
} | |
Spacer().frame(width: 10, height: :infinity) | |
} | |
Spacer().frame(width: :infinity, height: 5) | |
Text("最終更新: " + current).color(Color.hex("ffffff")) | |
Spacer().frame(width: :infinity, height: 10) | |
}.background(Color.hex("24292e")) | |
end | |
mainwidget.present |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
edited, thanks!