wco_email 0.1.1.53 → 0.1.1.55

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,126 +0,0 @@
1
-
2
- namespace :email do
3
-
4
- ## Not used until I revisit it. _vp_ 2023-04-02
5
- desc 'email:churn_mbox mbox_path=<filepath> '
6
- task churn_mbox: :environment do
7
-
8
- ## Usage
9
- if !ENV['mbox_path']
10
- puts ""
11
- puts "Usage: email:churn_mbox mbox_path=<filepath> "
12
- puts ""
13
- exit 22
14
- end
15
-
16
- which_file = ENV['mbox_path']
17
- message = nil
18
-
19
- # Tag
20
- tag_names = [
21
- File.basename( ENV['mbox_path'], '.*' ),
22
- "20230302-import",
23
- ]
24
- term_ids = tag_names.map do |tag_name|
25
- tag = WpTag.where( name: tag_name ).first
26
- tag ||= WpTag.my_create( name: tag_name, taxonomy: 'email_tag' )
27
- tag.id
28
- end
29
-
30
- client = Aws::S3::Client.new({
31
- region: ::S3_CREDENTIALS[:region],
32
- access_key_id: ::S3_CREDENTIALS[:access_key_id],
33
- secret_access_key: ::S3_CREDENTIALS[:secret_access_key] })
34
-
35
-
36
- File.readlines( which_file, encoding: "ISO8859-1" ).each do |line|
37
- if (line.match(/\AFrom /))
38
-
39
- ## @TODO: remove copy-paste [ref-1]
40
- if message
41
- the_mail = Mail.new(message)
42
- filename = the_mail.date.in_time_zone.to_s[0..18].gsub(' ', 'T').gsub(':', '_')
43
- filename = "#{filename}F#{the_mail.from[0].sub('@', '_').gsub('.', '_')}"
44
- flag = client.put_object({ bucket: ::S3_CREDENTIALS[:bucket_ses],
45
- key: filename,
46
- body: message,
47
- })
48
- @stub = ::Office::EmailMessageStub.create({
49
- object_key: filename,
50
- object_path: "https://#{::S3_CREDENTIALS[:bucket_ses]}.s3.amazonaws.com/#{filename}",
51
- state: ::Office::EmailMessageStub::STATE_PENDING,
52
- term_ids: term_ids,
53
- })
54
- if @stub.persisted?
55
- Ishapi::EmailMessageIntakeJob.perform_later( @stub.id.to_s )
56
- else
57
- puts! @stub.errors.full.messages.join(", "), "111 Cannot save this stub: #{@stub.id}."
58
- end
59
- print '.'
60
- end
61
- message = ''
62
-
63
- else
64
- message << line.sub(/^\>From/, 'From')
65
- end
66
- end
67
-
68
- ## @TODO: remove copy-paste [ref-1]
69
- if message
70
- the_mail = Mail.new(message)
71
- filename = the_mail.date.in_time_zone.to_s[0..18].gsub(' ', 'T').gsub(':', '_')
72
- filename = "#{filename}F#{the_mail.from[0].sub('@', '_').gsub('.', '_')}"
73
- flag = client.put_object( bucket: ::S3_CREDENTIALS[:bucket_ses],
74
- key: filename,
75
- body: message )
76
- @stub = ::Office::EmailMessageStub.create({
77
- object_key: filename,
78
- object_path: "https://#{::S3_CREDENTIALS[:bucket_ses]}.s3.amazonaws.com/#{filename}",
79
- state: ::Office::EmailMessageStub::STATE_PENDING,
80
- term_ids: term_ids,
81
- })
82
- if @stub.persisted?
83
- Ishapi::EmailMessageIntakeJob.perform_later( @stub.id.to_s )
84
- else
85
- puts! @stub.errors.full.messages.join(", "), "222 Cannot save this stub: #{@stub.id}."
86
- end
87
- print '.'
88
- end
89
- message = ''
90
-
91
- puts "ok"
92
- end
93
-
94
- ## Not used until I revisit it. _vp_ 2023-04-02
95
- desc 'after lambda puts object_key in mdb'
96
- task churn_messages: :environment do
97
- Office::EmailMessageStub.pending.each do |msg|
98
- Ishapi::EmailMessageIntakeJob.process_later( msg.id )
99
- end
100
- end
101
-
102
- desc 'be rake email:churn_one key_id=0ijbh58ocnat5oal6iqchn4rosj9q99u3opq37o1'
103
- task churn_one: :environment do
104
- object_key = ENV['key_id'] || 'iao4kfrcot6d3pd3hqp9af21e28iev6b5eoi6781'
105
- stub = MsgStub.find_or_create_by({ object_key: object_key }).update({ state: 'state_pending' })
106
- stub = MsgStub.find_by({ object_key: object_key })
107
- EIJ.new.perform( stub.id )
108
- end
109
-
110
- desc '2023-09-23 test 2'
111
- task :churn_leads_20230923 => :environment do
112
- Office::EmailConversation.all.each do |conv|
113
- conv.lead_ids.each do |lead_id|
114
- Office::EmailConversationLead.find_or_create_by({
115
- email_conversation_id: conv.id,
116
- lead_id: lead_id,
117
- })
118
- print '.'
119
- end
120
- puts '^'
121
- end
122
- end
123
-
124
- end
125
-
126
-
@@ -1,23 +0,0 @@
1
- require 'redd'
2
-
3
- namespace :reddit do
4
-
5
- desc "reddit crawler 1 - sentiment of gmejungle ?"
6
- task :crawl_1 => :environment do
7
- session = Redd.it({
8
- user_agent: 'Redd:IshBot:v0.0.0',
9
- client_id: '<>',
10
- secret: '<>',
11
- })
12
-
13
- top = session.subreddit('gmejungle').top
14
- submission = top[1]
15
- byebug
16
- puts! submission.self_text, 'self text'
17
-
18
- end
19
-
20
- end
21
-
22
-
23
-
@@ -1,146 +0,0 @@
1
-
2
- require 'httparty'
3
- require 'json'
4
-
5
- require_relative './ish/sitemap'
6
- require_relative './pi/sitemap'
7
- require_relative './wco/sitemap'
8
-
9
- def puts! args, label=""
10
- puts "+++ +++ #{label}"
11
- puts args.inspect
12
- end
13
-
14
- ##
15
- ## curl https://piousbox.com/index.php?p=2399 -I -H 'Cache-Control: no-cache, no-store'
16
- ##
17
-
18
- NAMESPACES = %w| Ish Wco Pi |
19
-
20
- namespace :sitemap do
21
-
22
- desc 'be rake sitemap:export namespace=Ish|Pi|Wco [ origin="https://wasyaco.com" ] '
23
- task :export => :environment do
24
-
25
- if !ENV['namespace']
26
- puts "Usage: "
27
- puts 'be rake sitemap:export namespace=Ish|Pi|Wco [ origin="https://wasyaco.com" ] '
28
- exit
29
- end
30
-
31
- if !NAMESPACES.include?( ENV['namespace'] )
32
- puts "Available namespaces: "
33
- puts NAMESPACES
34
- exit
35
- end
36
-
37
- origin = ENV['origin'] || "#{ENV['namespace']}::Sitemap".constantize::DEFAULT_ORIGIN
38
-
39
- out = "#{ENV['namespace']}::Sitemap".constantize.new.checks.select do |item|
40
- item[:selector].present? && !item[:private]
41
- end
42
- out.each do |check|
43
- puts "#{origin}#{check[:path]}"
44
- end
45
-
46
- end
47
-
48
- desc 'be rake sitemap:text namespace=Ish|Pi|Wco [ origin="http://wco_local:8088" ] '
49
- task :test => :environment do
50
-
51
- if !ENV['namespace']
52
- puts "Usage: "
53
- puts 'be rake sitemap:test namespace=Ish|Pi|Wco [ origin="https://wasyaco.com" ] '
54
- exit
55
- end
56
-
57
- if !NAMESPACES.include?( ENV['namespace'] )
58
- puts "Available namespaces: "
59
- puts NAMESPACES
60
- exit
61
- end
62
-
63
- results = []
64
- total_count = 0
65
- error_count = 0
66
-
67
- origin = ENV['origin'] || "#{ENV['namespace']}::Sitemap".constantize::DEFAULT_ORIGIN
68
-
69
- "#{ENV['namespace']}::Sitemap".constantize.new.checks.each do |check|
70
- total_count += 1
71
-
72
- # puts "Checking #{check[:path]}:"
73
- if check[:selector]
74
- begin
75
- body = HTTParty.get( "#{origin}#{check[:path]}" ).body
76
- rescue OpenSSL::SSL::SSLError => err
77
- results.push "NOT OK [ssl-exception] #{check[:path]}".red
78
- next
79
- end
80
- doc = Nokogiri::HTML( body )
81
- out = doc.search check[:selector]
82
- if out.present?
83
- results.push "OK #{check[:path]}"
84
- else
85
- results.push "NOT OK [selector-missing] #{check[:path]}".red
86
- error_count += 1
87
- end
88
-
89
- if check[:meta_description]
90
- out = doc.search( 'head meta[name="description"]' )[0]['content']
91
- if check[:meta_description] == out
92
- results.push "OK #{check[:path]} meta_description"
93
- else
94
- results.push "NOT OK [meta-description-missing] #{check[:path]}".red
95
- error_count += 1
96
- end
97
- end
98
-
99
- elsif check[:redirect_to]
100
- out = HTTParty.get( "#{origin}#{check[:path]}", follow_redirects: false )
101
- if( out.headers[:location] == check[:redirect_to] ||
102
- out.headers[:location] == "#{origin}#{check[:redirect_to]}" )
103
- results.push "OK #{check[:path]}"
104
- else
105
- results.push "NOT OK [redirect-missing] #{check[:path]}".red
106
-
107
- puts!( out.response, 'response' ) if DEBUG
108
- # puts!( out.body, 'body' ) if DEBUG
109
-
110
- error_count += 1
111
-
112
- puts "NOT OK #{check[:path]}".red
113
- puts out.headers[:location]
114
- puts check[:redirect_to]
115
- end
116
- else
117
- results.push "SKIP #{check[:path]}"
118
- end
119
-
120
- if check[:selectors]
121
- check[:selectors].each do |selector|
122
- body = HTTParty.get( "#{origin}#{check[:path]}" ).body
123
- doc = Nokogiri::HTML( body )
124
- out = doc.search selector
125
- if out.present?
126
- results.push "OK #{check[:path]} selectors:#{selector}"
127
- else
128
- results.push "NOT OK [selectors-missing:#{selector}] #{check[:path]}".red
129
- error_count += 1
130
- end
131
- end
132
- end
133
-
134
- end
135
-
136
- puts "Results:".green
137
- results.each do |r|
138
- puts r
139
- end
140
- puts "Total count: #{total_count}"
141
- puts "Error count: #{error_count}"
142
- end
143
-
144
- end
145
-
146
-