Skip to content
Snippets Groups Projects
Commit b46875db authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

Merge branch 'f-tsv-file-to-xsl' into 'dev'

F tsv file to xsl

See merge request caosdb/caosdb-server!17
parents 5ba6251d 6bba8a88
No related branches found
No related tags found
No related merge requests found
......@@ -31,27 +31,18 @@ import sys
import pandas as pd
def _parse_to_dataframe(csv_string):
"""Attempts to create a valid dataframe from a CSV string.
def _parse_to_dataframe(tsv_file):
"""Attempts to create a valid dataframe from a TSV file.
The CSV string typically starts with a header like this:
```
data:text/csv;charset=utf-8,colname1 colname2
value1 value2
...
```
Parameters
----------
csv_string : The URL encoded CSV content, starts with `data:text/csv`.
tsv_file : path to a tsv file.
Returns
-------
out : The created dataframe.
"""
csv_string = csv_string.split(",")[1]
sio = io.StringIO(csv_string)
dataframe = pd.read_csv(sio, sep="\t")
dataframe = pd.read_csv(tsv_file, sep="\t")
return dataframe
......@@ -101,19 +92,17 @@ def _parse_arguments():
tempdir = os.environ["SHARED_DIR"]
parser.add_argument('-t', '--tempdir', required=False, default=tempdir,
help="Temporary dir for saving the result.")
parser.add_argument('-u', '--urlencoded', required=True,
help="The URL encoded csv data.")
parser.add_argument('-a', '--auth-token', required=False,
help="An authentication token (not needed, only for compatibility).")
parser.add_argument('tsv', help="The tsv file.")
return parser.parse_args()
def main():
args = _parse_arguments()
dataframe = _parse_to_dataframe(args.urlencoded)
dataframe = _parse_to_dataframe(args.tsv)
filename = _write_xls(dataframe, directory=args.tempdir)
print(filename)
if __name__ == "__main__":
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment