-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomment.rb
28 lines (24 loc) · 918 Bytes
/
comment.rb
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
username = "sirmegamu" # GitHub 用户名
new_token = "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" # GitHub Token
repo_name = "sirmegamu.github.io" # 存放 issues
sitemap_url = "https://megamu.icu/sitemap.xml" # sitemap
kind = "Gitalk" # "Gitalk" or "gitment"
require 'open-uri'
require 'faraday'
require 'active_support'
require 'active_support/core_ext'
require 'sitemap-parser'
sitemap = SitemapParser.new sitemap_url
urls = sitemap.to_a
conn = Faraday.new(:url => "https://api.github.com/repos/#{username}/#{repo_name}/issues") do |conn|
conn.basic_auth(username, token)
conn.adapter Faraday.default_adapter
end
urls.each_with_index do |url, index|
title = open(url).read.scan(/<title>(.*?)<\/title>/).first.first.force_encoding('UTF-8')
response = conn.post do |req|
req.body = { body: url, labels: [kind, url], title: title }.to_json
end
puts response.body
sleep 15 if index % 20 == 0
end