Six months ago, I announced my own blogging script, b.py (PyPI). Just a few hours ago, a new release was tagged as Version v0.5.0, half way to the v1.0.0.
1 What has changed?
To be honest, it didn’t gain many features. It’s not I was stalling writing the code, but Blogger does. The API v3 hasn’t got any improvements since then. I have been waiting for page support, but it has not yet added, and I have no idea when Blogger will. I even asked in developer’s group, but it’s just a standard response and no follow-ups since then.
Nonetheless, one major feature is link checking with lnkckr, which ensures you link properly. No more accidentally broken links as long as you make sure you check your post. Also some minor fixes, tests, and more options for handlers.
2 How I blog from command-line and Vim
With my brc.py, vimrc, and preview template, I usually blog with the following process:
create a new reStructuredText source file and edit it in Vim.
b.py supports reST, Markdown, HTML, or plain text. But I have been using reST for a while and it’s the best in my opinion, because of its extensibility if you can code for your needs.
F5 to generate preview and open /tmp/preview.html in browser.
This is same as running b.py generate foobar.rst in command-line.
edit more and fix spelling.
,chk to check links, make sure I don’t mess up linking.
This is same as running b.py checklink foobar.rst in command-line.
,post to publish the blog post.
This is same as running b.py post foobar.rst in command-line.
Once the post is published, the source is edited by b.py to insert more metadata. Vim will ask me if I want to load the edited version, L to load it.
Check the actual published post to make sure everything is correct. If I mess up something, fix the post, then do the post command to update the post.
If everything is correct, I add the source file to my blog post repository.
3 Why I am writing this post?
I hope this will get people to know about b.py, I know many people can at least write in Markdown because of StackOverflow and/or GitHub, and some of them may be bloggers on Blogger. My way of blogging is more efficient and you don’t need to deal with typesetting or curse Blogger’s WYSIWYG editor because it somehow doesn’t want to give your the style you demand.
You may have known GoogleCL, unfortunately, it was never a viable option. Before b.py, it’s b.sh, which was a Bash script utilized GoogleCL. But GoogleCL uses Blogger API v2, which has a big issue with <br/> and Blogger doesn’t seem to care about it. Short answer is it messes up your post. I was left no choice but moved onto API v3 with my own script, but the lack of updates on v3 makes me wonder if I should’ve just switched to another blogging platform.
Since I started using b.py, I had only gone to the Blogger’s interface to post a single post. Just once, which was an empty post. It’s much efficient and more robust. I have all changes of most of my blog posts, any edits or fixes are all committed. They are all in reST or Markdown, so I have a copy of my posts, which is more portable than Blogger XML Export.
If one day I want to go somewhere, it’s easier. Yes, there must be some official importer, but you can’t be sure new platform will 100% parse the HTML from Blogger correctly. If the new platform accepts same lightweight markup language, it’s pain-free. That’s why I claim this way is more portable.
Hi Yu-Jie
ReplyDeleteI am trying to use your code located here:
https://bitbucket.org/livibetter/b.py on a Windows machine
If fails whit the following errors
c:\Python26\Scripts>..\python.exe b.py post test.html
Loading local configuration...
Cannot load module bpy\handlers\html of handler HTML
Traceback (most recent call last):
File "b.py", line 172, in find_handler
_mod_data = imp.find_module(hdlr['module'], search_path)
ImportError: No module named bpy\handlers\html
No handler for the file!
Can you please help me with this
Thanks
PS: I need this just to upload HTML files already formatted by another program
This definitely is a bug or at least an issue. Unfortunately, I could not provide support for OSes other than Linux. However, I do hope some people would help to port for other OSes.
ReplyDeleteIf you have time, please open an issue in issue tracker with the errors you get.
After some thoughts, I thought it might be difference between Python 2.6 and 2.7, but I checked the imp module, there was no notes about these two versions.
ReplyDeleteSo, I put b.py main script and make sure b.py library isn't importable from the location and I got the exactly the same error message on Linux.
Now, this looks more like a user error.
@Last Unicorn b.py main script needs its bpy library. You need to put that bpy folder alongside b.py script. Or you may want to study how to install b.py via pip on Windows. Please do report back if it does work on Windows, if you can successfully post, then I can add Windows to the package metadata.
Hi livivetter
ReplyDeleteIt shouldn't be a problem to get this working under Windows
It looks like a path problem, I am note extremely skilled with Python and I am not sure if I can fix this. I vaguely remember that there are differences beween path handling in Windows and Unix. I saw that in a source for a program that was working on both, Windows and Unix
The installation script worked and the files landed in folders as described below:
-b.py is in c:\Python26\Scripts
The bpy folder is C:\Python26\Lib\site-paclages\bpy
Normally the find_handler function should be able to find the HTML handler.
Since HTML does not do much is there any any markup codes that I can add to my HTML and then bypass the handler import procedure?
My HTML file is generated by another python script, I could probably modify that
Thanks in advance
LU
Could you open an issue, so we can track the problem properly?
ReplyDeletePlease also attach current error message and how you install b.py along with your system/Python information.
I also want you to try something, they are different things: (please also attach to issue report)
* Launch Python interactive mode, run import bpy.handlers.html to see if HTML handler can be imported.
* Unzip b.py to somewhere (download zip from bitbucket), run directly without installing, make sure system-wide installed b.py has been removed before you try.
Done.
ReplyDeleteDamn ...it's issue 13 (bad luck in western tradition) :D
Thanks for opening the issue, I would try to fix it later.
ReplyDeleteOne more question: can you please help me to understand how I can call your script from another python script? I have tried to import the functions you defined but it looks like the main function is always trying to process the command line arguments which do not exist if you call the functions from another script. Could you please guide me what to do /
ReplyDeletethanks a lot
LU
Because it is written to be used as a command-line program. If you want to use main() from another script, you need to manipulate sys.argv, read Pythong's argparse documentation.
ReplyDeleteThe best suggestion I can give is to make the markup file, and do a system call to post.
If you aren't familiar with Python, I suggest you just write a batch file to automate whatever process you need to do.