Scripting’s Every Otaku’s Dream! 编写脚本是每个宅的梦想

I’m evil, because I’ve wasted one more days on the god damn Ac Search Tool, only complicating it with OO, but with little code-reuse.

我有罪,因为我在那个可恶的AC娘搜索工具上又花了一天时间,只是用面向对象的方法来将它复杂化,没有任何的代码重用。

But I can’t help to keep developing it.

但我忍不住想继续改进这个工具。

Then I read the update of an ACG blog, author of which must be otaku undoubtedly. He said he was eventually idle at the end of the year, maybe idle enough to code. So I reached the conclusion of the title. But let’s talk more about it.

然后我看到一个ACG博客更新了,博客作者肯定也是个死宅。他说他在年末终于闲下来了,手痒得想写代码。所以我得出了标题的结论。但是再深入讨论一下吧。

Have you ever been in a task, that you have to keep doing the same thing everyday or each hour?

你有没有尝试过做一项工作,需要每天甚至每小时做同样的事情?

If so, have you ever considered that you would be bored and tried to make it automatically?

如果有的话,你有没有想过你会感到厌倦,然后想办法让这件事自动做好?

Here I mean to reduce one self’s workload, not others’ because it involves offices of the arts; besides, it’s better that you finish your work earlier than your workmate with the same work, but it’s going too far. To make a task automatically is not as difficult as you’ve ever thought. If you have to run a program or a command regularly, who not use Task Scheduler of your windows? Of coz there are various tasks that much more complex than running a command, but we have Quick Marco; Further, for instance, when you have to login to a website from which you grasp some data (of coz regularly), just turn to scripts.

这里我说的是减轻自己的工作量,而不是别人的,因为这涉及办公室艺术;此外,同样的工作你比你的同事完成得更快是一件好事,扯远了。使一项任务自动化并不像想象中那么困难,如果你需要定期运行一个程序或一个命令,为什么不用windows的计划任务去搞定它呢?当然任务在很多时候比运行一个命令要复杂得多,但我们有按键精灵;更长远的例如,你需要登录到一个网站然后从上面抓取数据(定期抓取),可以考虑用脚本语言。

When you are dealing with such regular tasks, but without any batched or automatic solutions, I think you have been wasting human resource of yourself and your company lol. You may argue that you’ve found your work tasks unstructured, your decision non-programmed, but you should have reconsidered you work first. According to management, superiors are always empower their subordinates to work out well-structured problems and programmed decisions so that they can focus on the unstructured and non-programmed ones. Assume that you have no subordinates to empower, because of which you are otaku XD, you must have had dozens of well-structured problems and programmed decisions, rest with whether you’ve induced them.

当你在处理这样的常规任务时,没有任何批处理或者自动化的解决方案,我觉得是在浪费自己和公司的人力资源。你可能会说你觉得自己的工作全都是非结构化的,决策都是非程序化的,但在这之前你应该重新考虑自己的工作。根据管理学,上司总是将结构良好的问题和程序化决策授权给下属去完成,以便自身集中对付那些结构不良问题和非程序化决策。假设你没有下属可以授权(因为你死宅XD),那你肯定攒了很多结构良好的问题和程序化决策了,只是你没有归纳出来而已。

So don’t wait to be bored, spare a little time to study a scripting language now. Points:

那么不要等到厌烦了的时候,现在就花一点时间学一种脚本语言吧。一些指南:

  1. Glad that there are various scripts, such as vbs, js, ruby and python. You can find info from Google, choose one that agree with your habits of mind. Scripts related to Rapid Development may be better.
  2. It’s important to weigh and consider balance time between scripting and keep repeating, but you should not do that until you can write scripts craftily, so study first.
  3. Do not help others, or they will keep boring you! ╮(╯_╰)╭

 

  1. 让人高兴的是脚本语言有很多种,例如vbs、js、ruby和python。你可以Google它们,然后找一种适合自己思维习惯的。那些和快速开发有关的语言会好一点。
  2. 虽然权衡写脚本和继续重复劳动的时间是很重要的事情,不过最好等你熟练使用脚本语言了再权衡吧,所以学了再说。
  3. 不要用来帮助别人,不然他们会烦死你!╮(╯_╰)╭

That’s it. I strongly recommended python, undoubtedly not because I only know it (grasping my hair)……

就这样了,我强烈推荐python,这绝不是因为我只会这种语言(抓头发)……

Developing Search Tool for Acfun

When the self-owned search function was cancel by the monkey, I planned to develop this tool. After thinking and strolling in my room for 2 hours, I thought I had known what to do and started to make it.

当猿把ac娘自带的搜索引擎吞了,我便开始计划做这个工具。经过2小时的构想和到处乱走,我感到自己已经知道要怎样弄了,于是开工。

Python, which I fought for this semi-finished Acfun Search Tool with, was new for me 3 days ago. I had a chance to choose a script to develop the tool, for I’ve know nothing about technique newer than JAVA. Finally I chose Python, because:

我花了3天完成现在的半成品,用的是Python,一种从来没用过的语言。我可以考虑用任何脚本语言,反正所有比JAVA要新的语言我都不会用。用Python的原因是:

  1. It worked immediately after it was installed without any other configurations.
  2. It ran as a double-click rather than “python yourname.py<enter>”, like VBScript. It is much shorter, isn’t it?
  3. For the reality. Google App Engine has supported it, and I meant to put the tool there to benefit from the powerful Google. Later I realized that GAE has maximum of 1M for data-transfer, so I changed my hosting place.
  1. 装好以后就可以用了,不用任何附加设置。
  2. 程序文件双击就可以执行,像VBS一样,不需要用命令行执行。对我来说这很重要,因为够简单,哈哈。
  3. 实际上是因为Google App Engine支持它。原本我打算在GAE上放这个程序,以便利用实力强大的Google,但我很快发现GAE只支持1M以内的数据读写,于是我改放到其它免费空间中。

At the very start, I planned to fecth all the data from acfun.cn first, keep it up to date, and built a RSS feed for it so others can secondary exploite it, but I decide to finish the search function first. I spent 2 days grabing datas from Acfun, modifying my crawler to suit to the irregular but met frequently data for several times, and change the data-structure from CSV file to SQLite database(CSV has been used for GAE). When Acfun became busy at prime time, I had to pause the crawler.

最初我打算先抓取全部数据,然后制作RSS,那样其他人也可以用这些数据来二次开发,但我决定还是先做出搜索功能。花了2天去抓数据,途中对爬虫进行了几次修改,又将数据格式从csv改成SQLite数据库(当初考虑用csv是因为GAE)。当Acfun进入访问黄金时间,就只能暂停抓取。

Finally the crawler accompalished its mission and was reformed to keep the data new. I’ve been aware of Python web frameworks such as django, but I decided to use CGI script, because it’s much easier for me who knows nothing about frameworks or MVCs or MVTs. When I directly use the hosting to test my scripts, my work increasing geometrically. Now it works, although hardly with user-interface.

数据抓完后,我便将爬虫改成数据更新器。虽然留意了很多Python的web架构,但我完全不懂那些东西,所以还是决定用最简单的Python CGI Scripts。因为要在远程服务器上调试,所以工作量非常大,无论如何现在是弄好了,但几乎没有任何用户界面……能用就行。

I’ve published to TIEBA of Acfun so as to ease maybe some load of Acfun Server. I hope people will benefit from it, and I have to go back to revise now. Visit @ http://illustrate.heliohost.org/ac.htm.

已经在Acfun吧发布了,希望能够帮到人并且减轻Ac娘的负担,我要回到复习状态……访问上面的网址就可以使用这个工具。