我知道可以使用Github API通过各种标准 搜索存储库,但如何搜索单个要点或找到其ID?
理想情况下,我想使用
理想情况下,我想使用
用户
和文件名
,但它也可能是内容主体内的哈希值:https://gist.github.com/search?q=sadjghasghdhjasgdfhs
用户
和文件名
,但它也可能是内容主体内的哈希值:https://gist.github.com/search?q=sadjghasghdhjasgdfhs
在GitHub社区的评论中给出的顶级答案不再适用。我从archive.org中提取了Ruby示例,如下所示:
module GistSearch
class << self
def search_public_gists(query:, page_limit: 10)
docs = []
base_url = "https://gist.github.com"
next_path = "/search?q=#{query}"
page_limit.times do
url = "#{base_url}#{next_path}"
html = fetch_cached(url)
doc = Nokogiri(html)
docs << doc
if !doc.search("a[rel=next]").empty?
next_path = doc.search("a[rel=next]").attr("href").value
else
break
end
end
docs
end
def build_items(queries:)
queries.flat_map do |query|
search_public_gists(query: query).flat_map do |doc|
doc.
search(".gist-snippet").
map do |gist_snippet|
Item.new(
creator: gist_snippet.search(".creator a:first").text,
title: gist_snippet.search(".creator a").map(&:text).join(" / ") + " (Matched query: #{query.inspect})",
link: gist_snippet.search(".link-overlay").attr("href").value,
guid: gist_snippet.search(".link-overlay").attr("href").value,
pub_date: Time.iso8601(gist_snippet.search("time-ago").attr("datetime").value),
content: gist_snippet.search(".js-file-line").map(&:text).join("\n"),
)
end
end
end
end