Skip to content

Commit

Permalink
new file: comment.rb
Browse files Browse the repository at this point in the history
	modified:   sitemap.xml
  • Loading branch information
Mega-MU committed Jan 4, 2023
1 parent a02644b commit 692a6cf
Show file tree
Hide file tree
Showing 2 changed files with 216 additions and 3 deletions.
28 changes: 28 additions & 0 deletions comment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
Loading

0 comments on commit 692a6cf

Please sign in to comment.