红宝石是为了浪漫?如何从脚本自身更新脚本
当我利用我的极客能力变得“浪漫”时,我的妻子很喜欢它,所以我想到了在她的 Mac 上安装一个 ruby 脚本的想法,该脚本可以全天向她发送我的引言和小笔记。 我已经知道我将使用 GeekTool 在后台运行脚本,并且我将使用 Growlnotify 来显示消息。 现在我需要的是一种从网络更新脚本的方法,以防我更改它。 除了如何与控制台交互之外,我对 ruby 基本上一无所知。
我有2个目标: 1) 有一个包含消息的 XML 文件。这需要可以从互联网上更新,但必须是本地的,以防她没有网络连接。 2)从互联网上更新脚本本身,以防我发现错误或想要改进它。
现在我知道,如果我愿意的话,我显然可以手动更新她的 Mac 上的脚本,但我认为这将是学习一些更高级的 ruby 的好方法。
优先级 1 是 XML 文件,如果发生更改,能够下载新版本。我可以使用什么 ruby 工具来下载文件并将其保存到本地某个位置?
我以前使用过 hpricot,这是一个好方法吗?
注意:我妻子的 Mac 是 Macbook,运行 Leopard(但可能是 10.4,不是 100% 确定)。
编辑
如果有人对该脚本的第一个版本感兴趣,您可以找到它此处
ps -->该脚本的第一个版本实际上并不更新自身,它只是更新 messages.xml 文件,仅此而已。
My wife enjoys it when I use my geek abilities to be "romantic" so I had an idea for a ruby script to install on her Mac that would send her quotes and little notes from me throughout the day.
I already figured out that I'll be using GeekTool to run a script in the background and I'll use growlnotify to display the messages.
Now what I need is a way to update the script from the web in case I change it.
I know basically nothing about ruby other than how to interact with the console.
I have 2 goals:
1) Have an XML file with messages. This needs to be update-able from the internet, but be local in case she doesn't have a network connection.
2) Update the script itself from the internet in case I find bugs or want to improve it.
Now I know that I could obviously just manually update the script on her Mac if I wanted to, but I figured this would be a good way to learn some more advanced ruby.
Priority 1 would be the XML file, be able to download a new version if it changes. What ruby things can I use to download a file and save it to a certain place locally?
I have used hpricot before, would that be a good way to go?
Note: My wife's mac is a Macbook, running Leopard (but maybe 10.4, not 100% sure).
EDIT
If anyone is interested in the first version of the script you can find it here
p.s. --> the first version of the script doesn't update itself actually, it just updates the messages.xml file and that's all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
类似的东西应该有效。您也可以下载 Ruby 脚本,然后调用。
Something like that ought to work. You can download the Ruby script too, then call.
如果您有一个包含全天随机发送的 xml 消息的文件,您的妻子不会看到您来吗?您发送消息并让她立即收到不是更好吗?
您可以使用 XMPP 协议来执行此操作。
你妻子的应用程序将自身连接到 XMPP 服务器;你也是。您可以随时向她发送消息。
您甚至可以强制在每条消息之间以一定的时间间隔发送消息。
因此,当她在没有任何互联网连接的情况下流浪时,您知道这一点,您可以提前向她发送 3 或 4 条消息。她稍后会收到它们。
对于脚本更新,这与任何网站服务器遇到的问题类似。
因此,我会在她的计算机上打开一个 SSH 端口,并使用 capistrano 来部署最应用程序的最新版本。
Won't your wife see you coming if you have a file with xml messages coming randomly through the day ? Wouldn't it be better for you to send a message and for her to receive it instantly ?
You could use the XMPP protocol to do so.
Your wife's application connects itself to the XMPP server; you too. And you can send her a message whenever you want to.
You could even force the messages to be sent with some distance in time between each one of them.
So when she's going nomad without any internet connexion and you know it, you send her 3 or 4 messages by advance. And she'll receive them later.
For the script update, it's a similar problem than what you'd have with any website server.
So I'd open a SSH port on her machine and use capistrano to deploy the most recent version of the application.
消息有多长?如果 XML 很短,那么它可能有点过大了。为什么不只使用每行一条消息的文本文件?
使用 GeekTool 来运行脚本可能也没有必要。您只需使用
nohup myscript.rb
启动脚本,它将继续运行,直到您终止该进程。How long are the messages? XML might be a little overkill if they're short. Why not just use a text file with one message per line?
Using GeekTool to run the script is probably not necessary either. You can just start the script with
nohup myscript.rb
and it will keep running until you kill the process.