Skip to content

Instantly share code, notes, and snippets.

@mikz
Created October 8, 2021 15:32
Show Gist options
  • Save mikz/7b793e5b2b6bf4c95f67707e8fc9cd30 to your computer and use it in GitHub Desktop.
Save mikz/7b793e5b2b6bf4c95f67707e8fc9cd30 to your computer and use it in GitHub Desktop.

Revisions

  1. mikz created this gist Oct 8, 2021.
    14,985 changes: 14,985 additions & 0 deletions Rules.1b
    14,985 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
    31 changes: 31 additions & 0 deletions generator.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    #!/usr/bin/env ruby
    require 'csv'
    require 'open-uri'
    require 'json'

    uri = URI.open('https://www.coi.cz/userdata/files/dokumenty-ke-stazeni/open-data/rizikove.csv')

    domains = CSV.read(uri).to_a.flatten

    $globalid = 0

    def generate_id
    $globalid += 1
    "B8C7FA8A-66E8-400F-AB2B-C36E64DD%05d" % $globalid
    end

    def make_rule(domain)
    {
    id: generate_id,
    name: domain, content: {trigger: {"url-filter"=>"https?://+([^:/]+\\.)?#{domain}[:/]", "url-filter-is-case-sensitive"=>false}, action: {type: 'block'}}}
    end

    puts JSON.pretty_generate([{
    rules: domains.flat_map(&method(:make_rule)),

    id: "BFA55950-8BEF-4391-B263-3C67BDFC0362",
    name: "Rizikové weby podle ČOI",

    createdAt: 655398187.740042
    }
    ])