1
1
#!/usr/bin/env python3
2
- #===============================================================================
2
+ # ===============================================================================
3
3
#
4
4
# FILE: hxl2pandas
5
5
#
10
10
# table are mostly as reference of how pandas (more specifically
11
11
# DataFrame) could be used as an intermediate format to export
12
12
# HXL to other formats already supported by Pandas.
13
- #
13
+ #
14
14
# While the reference table may still be useful for those who
15
15
# are doing manual conversionor to help understand how different
16
16
# tools used for data mining / machine learningwould use HXL
31
31
# VERSION: v1.0-draft
32
32
# CREATED: 2021-01-36 03:43 UTC v1.0 imported from hxl2example
33
33
# REVISION: ---
34
- #===============================================================================
34
+ # ===============================================================================
35
35
36
36
import sys
37
37
import os
@@ -43,6 +43,9 @@ import hxl.converters
43
43
import hxl .filters
44
44
import hxl .io
45
45
46
+ import tempfile
47
+ import time
48
+
46
49
# In Python2, sys.stdin is a byte stream; in Python3, it's a text stream
47
50
STDIN = sys .stdin .buffer
48
51
@@ -65,6 +68,8 @@ class HXL2Pandas:
65
68
self .EXIT_ERROR = 1
66
69
self .EXIT_SYNTAX = 2
67
70
71
+ self .original_outfile = None
72
+
68
73
def make_args_HXL2Pandas (self ):
69
74
70
75
self .hxlhelper = HXLUtils ()
@@ -84,12 +89,29 @@ class HXL2Pandas:
84
89
called will convert the HXL source to example format.
85
90
"""
86
91
87
- # NOTE: the next lines, in fact, only generate an csv outut. So you
88
- # can use as starting point.
89
- with self .hxlhelper .make_source (args , stdin ) as source , \
90
- self .hxlhelper .make_output (args , stdout ) as output :
91
- hxl .io .write_hxl (output .output , source ,
92
- show_tags = not args .strip_tags )
92
+ # If the user specified an output file, we will save on
93
+ # self.original_outfile. The args.outfile will be used for temporary
94
+ # output
95
+ if args .outfile :
96
+ self .original_outfile = args .outfile
97
+
98
+ try :
99
+ temp = tempfile .NamedTemporaryFile ()
100
+ args .outfile = temp .name
101
+
102
+ # NOTE: the next lines, in fact, only generate an csv outut. So you
103
+ # can use as starting point.
104
+ with self .hxlhelper .make_source (args , stdin ) as source , \
105
+ self .hxlhelper .make_output (args , stdout ) as output :
106
+ hxl .io .write_hxl (output .output , source ,
107
+ show_tags = not args .strip_tags )
108
+
109
+ print ('Temporary HXLated csv at ' , args .outfile )
110
+ print ('TODO: implement the conversion' )
111
+ time .sleep (20 )
112
+
113
+ finally :
114
+ temp .close ()
93
115
94
116
return self .EXIT_OK
95
117
0 commit comments