Skip to content

Instantly share code, notes, and snippets.

@installero
Last active August 10, 2022 15:20
Show Gist options
  • Save installero/44df53efc851036174c2aaebb9bc46e5 to your computer and use it in GitHub Desktop.
Save installero/44df53efc851036174c2aaebb9bc46e5 to your computer and use it in GitHub Desktop.

Revisions

  1. installero revised this gist Aug 10, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions stop_forum_spam.rb
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # https://www.stopforumspam.com/usage

    # require 'byebug'
    require 'httparty'

  2. installero created this gist Aug 10, 2022.
    38 changes: 38 additions & 0 deletions stop_forum_spam.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    # require 'byebug'
    require 'httparty'

    url = 'http://api.stopforumspam.org/api';

    username, email, ip = ARGV[0..2]

    data = {username: [username], email: email, ip: ip}

    response = HTTParty.post(url, query: data, format: :xml)
    check_results_hash = response['response']

    # {
    # username: {appears: false},
    # email: {appears: true, frequency: 321, last_seen_at: '2022-07-18 16:44:41'},
    # ip: {appears: true, frequency: 2875, last_seen_at: '2022-08-02 23:02:01'}
    # }

    result = {}
    last_seen_index_offset = 0

    check_results_hash['type'].each.with_index do |field_name, index|
    appears = check_results_hash['appears'][index] == 'yes'

    result[field_name] = {appears: appears}

    unless appears
    last_seen_index_offset -= 1
    next
    end

    result[field_name].merge!({
    frequency: check_results_hash['frequency'][index],
    last_seen_at: check_results_hash['lastseen'][index + last_seen_index_offset]
    })
    end

    puts result.inspect