commit cb07309c378dbd11932e518b9ddf03f219f2f38a
parent cc6dded2c23a42728724f2de5d1c3a56d7b1f53e
Author: Nils Gillmann <gillmann@infotropique.org>
Date: Sun, 17 Jun 2018 13:01:35 +0000
create libextractor.examples.__main__ as entry_point
Signed-off-by: Nils Gillmann <gillmann@infotropique.org>
Diffstat:
1 file changed, 51 insertions(+), 0 deletions(-)
diff --git a/libextractor/examples/__main__.py b/libextractor/examples/__main__.py
@@ -0,0 +1,51 @@
+"""
+extract.py
+
+ This file is part of libextractor.
+ (C) 2002, 2003, 2004, 2005 Vidyut Samanta and Christian Grothoff
+ (C) 2017, 2018 Nils Gillmann <gillmann@n0.is>
+
+ libextractor is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ libextractor is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libextractor; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+Little demo how to use the libextractor Python binding.
+
+"""
+from __future__ import print_function
+from libextractor import extractor
+import sys
+from ctypes import *
+import struct
+
+
+xtract = extractor.Extractor()
+
+def print_k(xt, plugin, type, format, mime, data, datalen):
+ mstr = cast(data, c_char_p)
+ # FIXME: this ignores 'datalen', not that great...
+ # (in general, depending on the mime type and format, only
+ # the first 'datalen' bytes in 'data' should be used).
+ if (format == extractor.EXTRACTOR_METAFORMAT_UTF8):
+ print("%s - %s" % (xtract.keywordTypes()[type], mstr.value))
+ return 0
+
+def main():
+ # stuff
+ for arg in sys.argv[1:]:
+ print("Keywords from %s:" % arg)
+ xtract.extract(print_k, None, arg)
+
+if __name__ == "__main__":
+ main()