1 Star 0 Fork 0

苗晓雨/hacker-scripts

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
kumar_asshole.rb 1.03 KB
一键复制 编辑 原始数据 按行查看 历史
#!/usr/bin/env ruby
require 'dotenv'
require 'gmail'
Dotenv.load
GMAIL_USERNAME = ENV['GMAIL_USERNAME']
GMAIL_PASSWORD = ENV['GMAIL_PASSWORD']
GMAIL = Gmail.connect(GMAIL_USERNAME, GMAIL_PASSWORD)
KUMARS_EMAIL = 'kumar.a@example.com'
DB_NAME_REGEX = /\S+_staging/
KEYWORDS_REGEX = /sorry|help|wrong/i
def create_reply(subject)
GMAIL.compose do
to KUMARS_EMAIL
subject "RE: #{subject}"
body "No problem. I've fixed it. \n\n Please be careful next time."
end
end
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])
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)
# Restore DB
`gunzip -c #{backup_file} | psql #{db_name}`
# Mark as read, add label and reply
email.read!
email.label('Database fixes')
reply = create_reply(email.subject)
GMAIL.deliver(reply)
end
end
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mxy8086/hacker-scripts.git
git@gitee.com:mxy8086/hacker-scripts.git
mxy8086
hacker-scripts
hacker-scripts
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385