-
Notifications
You must be signed in to change notification settings - Fork 2
/
rahnama.thor
executable file
·68 lines (59 loc) · 1.83 KB
/
rahnama.thor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env ruby
require 'thor'
require './lib/capybara_config'
require './lib/scraper'
require './lib/plain_scraper'
require './lib/plain_scraper_for_rental'
require './lib/sqlite_config'
require './lib/telegram_bot'
require 'pry'
require 'json'
class Rahnama < Thor
option :proxy
option :browser
desc 'scrap_ads', 'Scrap the Rahnama.com Real Estate Ads based on provided links.txt'
def scrap_ads
if options[:browser] == "plain"
results= PlainScraper.new.start
else
CapybaraConfig.init options[:proxy], options[:browser]
results= Scraper.new.start
end
processor = RawAdProcessor.new results
processor.persist_ads
end
option :proxy
option :browser
desc 'scrap_rental_ads', 'Scrap the Rahnama.com Real Estate Ads based on provided links.txt'
def scrap_rental_ads
if options[:browser] == "plain"
results= PlainScraperForRental.new.start
else
CapybaraConfig.init options[:proxy], options[:browser]
results= Scraper.new.start
end
processor = RawAdProcessor.new results
processor.persist_ads
end
desc 'send', 'Send ads to Telegram Channel'
def send
bot= TelegramBot.new
bot.send
end
desc 'update_elasticsearch', 'Update Elasticsearch data'
def update_elasticsearch
ElasticsearchClient.import_ads
end
desc 'send_daily_digest', 'Send ads to Telegram Channel'
def send_daily_digest
bot= TelegramBot.new
bot.send_daily_digest
end
desc 'generate_dic', 'Generaet Dictionary based on Ads words'
def generate_dic
rows= $db.execute('select * from ads')
words= rows.map { |e| e[2] }.map { |e| e.split(/[\s,،]/).select { |e| e.length>1 } }.flatten
counts = words.each_with_object(Hash.new(0)) { |word, counts| counts[word] += 1 }
IO.write('./data/words.json', JSON.pretty_generate(counts.sort_by { |_, v| v }))
end
end