First, as kuyan suggested, see http://wiki.vg/Main_Page, which has links to various programs that may be useful, either directly or for source to look at.
For example, under Utilities, the first thing that comes up is a logging proxy.
And a bit down, there's mc3p
, the program suggested by Joran Beasley—a Python proxy, with plugin support. It only works up to 1.2.5, but sadimusi/mc3p
claims to be a 1.4.2-compatible fork. As J.F. Sebastian says, mc3p
has an interface for log plugins, so you can just write one that logs to postgres.
If you want to read the packets yourself, that's not hard. You can write a generic TCP proxy in a few dozen lines of Python—or write one in 2 lines of shellscript around netcat that tees the data to your Python script.
The hard part isn't intercepting the data; it's parsing the protocol. Minecraft probably isn't sending "Nightbane: 1 tnt for 100.000 Dollars each", but something like "offer:Nightbane:1:tnt:100" or "\x13\x09Nightbane\x00\x01\x72\x00\x64". From what the wiki says, the protocol is documented, but poorly, and sometimes inaccurately, and the wiki is sometimes incorrect too, and the official code is very ugly and hard to read. Which means that the best way to figure out the protocol is probably by reading sadimusi/mc3p or one of the other projects like McPacketSniffer or ProtoProxy, at which point you have to ask whether it would be easier to just use that project instead of reimplementing it.
At any rate, scraping the screen should be your last resort.