Add 'json.rb'
This commit is contained in:
parent
03144f711d
commit
dd15b52143
|
@ -0,0 +1,53 @@
|
|||
require 'json'
|
||||
require 'date'
|
||||
require 'lda-ruby'
|
||||
require 'lingua/stemmer'
|
||||
require 'textoken'
|
||||
require 'stopwords'
|
||||
require_relative 'lib'
|
||||
class Clean
|
||||
def initialize(line)
|
||||
@line = line
|
||||
end
|
||||
def line
|
||||
@line
|
||||
end
|
||||
def cleanize
|
||||
corpus = Lda::Corpus.new
|
||||
f = Stopwords::Snowball::Filter.new "en"
|
||||
cleaned_post = line.downcase
|
||||
text_token = Textoken(cleaned_post, exclude: 'punctuations').tokens
|
||||
filtered = f.filter(text_token)
|
||||
|
||||
return filtered
|
||||
end
|
||||
end
|
||||
class Json
|
||||
def initialize
|
||||
@date = DateTime.now.strftime("%m/%d/%Y")
|
||||
end
|
||||
def date
|
||||
@date
|
||||
end
|
||||
def save_file
|
||||
if !File.exists?("fucking_Work.json")
|
||||
File.open(File.join("fucking_Work.json"), "w") { |file| file.write("{}") }
|
||||
end
|
||||
@f_json = []
|
||||
json = JSON.parse(File.read("fucking_Work.json"))
|
||||
File.readlines("DarknetMarketsNoobs_urls.txt").each do |l|
|
||||
curl = Config.new.get_body
|
||||
curl = curl.gsub(".onion", ".onion#{l}")
|
||||
stdout, status = Open3.capture3(curl)
|
||||
page = Nokogiri::HTML(stdout)
|
||||
out = page.xpath("/html/body/div/div[2]/div[2]/div/div[2]/div").text.strip
|
||||
c = Clean.new(out).cleanize
|
||||
@f_json << c.join(" ")
|
||||
end
|
||||
p @f_json
|
||||
json[date] += @f_json
|
||||
File.open(File.join("fucking_Work.json"), "w") { |file| file.write(JSON.pretty_generate(json)) }
|
||||
end
|
||||
end
|
||||
|
||||
Json.new().save_file
|
Loading…
Reference in New Issue