diff --git a/upload.py b/upload.py new file mode 100644 index 0000000..64988a8 --- /dev/null +++ b/upload.py @@ -0,0 +1,59 @@ +import getopt +import re +import sys +import os +from os.path import getsize, isdir, isfile, join, dirname +import httplib2 +from lxml import html +import time +import random + + +import requests +from requests_toolbelt.multipart.encoder import MultipartEncoder + +def upload(csvFile): + + m = MultipartEncoder( + fields={ + 'file': ('0.csv', open(csvFile, 'rb'), 'text/csv'), + 'settings': ('csvReaderSettings.json', '{"separator":44,"columnDefinitions":{"columnDefinitions":{"tag":{"ignore":false,"renameTo":null,"postProcessors":["LOWER_CASE"]},"ignoredColumn":{"ignore":true,"renameTo":null,"postProcessors":[]}}},"additionalTags":{"additionalColumn":"additionalValue"},"timeColumn":"@timestamp","valueColumn":"duration","comment":35}', 'application/json') + }) + + r = requests.post('http://localhost:8080/data?waitUntilFinished=false', data=m, + #headers={'Content-Type': m.content_type}) + headers={ + 'Accept': 'text/plain, application/json, application/*+json, */*', + 'Content-Type': m.content_type.replace("form-data", "mixed;charset=UTF-8") + }) + + +def help(returnValue): + print(sys.argv[0] + ' --file ') + print('Examples: ') + print(sys.argv[0] + ' --file data.csv') + sys.exit(returnValue) + + +def main(argv): + csvFile = '' + try: + opts, args = getopt.getopt(argv,"hf:",["file="]) + except getopt.GetoptError: + help(2) + for opt, arg in opts: + if opt == '-h': + help(0) + elif opt in ("-f", "--file"): + csvFile = arg + + print(csvFile) + if not isfile(csvFile): + print("does not exist") + sys.exit(1) + upload(csvFile) + + sys.exit(0) + +if __name__ == "__main__": + main(sys.argv[1:])