mirror of
https://github.com/narkoz/hacker-scripts
synced 2025-08-23 02:47:14 +00:00
Merge pull request #58 from bitsapien/kumar_asshole_script_constants_problem
fixed issue with gmail, kumars_email variable scope
This commit is contained in:
commit
46dcd9e347
@ -8,21 +8,21 @@ Dotenv.load
|
|||||||
GMAIL_USERNAME = ENV['GMAIL_USERNAME']
|
GMAIL_USERNAME = ENV['GMAIL_USERNAME']
|
||||||
GMAIL_PASSWORD = ENV['GMAIL_PASSWORD']
|
GMAIL_PASSWORD = ENV['GMAIL_PASSWORD']
|
||||||
|
|
||||||
gmail = Gmail.connect(GMAIL_USERNAME, GMAIL_PASSWORD)
|
GMAIL = Gmail.connect(GMAIL_USERNAME, GMAIL_PASSWORD)
|
||||||
kumars_email = 'kumar.a@example.com'
|
KUMARS_EMAIL = 'kumar.a@example.com'
|
||||||
|
|
||||||
DB_NAME_REGEX = /\S+_staging/
|
DB_NAME_REGEX = /\S+_staging/
|
||||||
KEYWORDS_REGEX = /sorry|help|wrong/i
|
KEYWORDS_REGEX = /sorry|help|wrong/i
|
||||||
|
|
||||||
def create_reply(subject)
|
def create_reply(subject)
|
||||||
gmail.compose do
|
GMAIL.compose do
|
||||||
to kumars_email
|
to KUMARS_EMAIL
|
||||||
subject "RE: #{subject}"
|
subject "RE: #{subject}"
|
||||||
body "No problem. I've fixed it. \n\n Please be careful next time."
|
body "No problem. I've fixed it. \n\n Please be careful next time."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
gmail.inbox.find(:unread, from: kumars_email).each do |email|
|
GMAIL.inbox.find(:unread, from: KUMARS_EMAIL).each do |email|
|
||||||
if email.body.raw_source[KEYWORDS_REGEX] && (db_name = email.body.raw_source[DB_NAME_REGEX])
|
if email.body.raw_source[KEYWORDS_REGEX] && (db_name = email.body.raw_source[DB_NAME_REGEX])
|
||||||
backup_file = "/home/backups/databases/#{db_name}-" + (Date.today - 1).strftime('%Y%m%d') + '.gz'
|
backup_file = "/home/backups/databases/#{db_name}-" + (Date.today - 1).strftime('%Y%m%d') + '.gz'
|
||||||
abort 'ERROR: Backup file not found' unless File.exist?(backup_file)
|
abort 'ERROR: Backup file not found' unless File.exist?(backup_file)
|
||||||
@ -34,6 +34,6 @@ gmail.inbox.find(:unread, from: kumars_email).each do |email|
|
|||||||
email.read!
|
email.read!
|
||||||
email.label('Database fixes')
|
email.label('Database fixes')
|
||||||
reply = create_reply(email.subject)
|
reply = create_reply(email.subject)
|
||||||
gmail.deliver(reply)
|
GMAIL.deliver(reply)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user