Как импортировать данные (формат JSON) в hbase в python - PullRequest
0 голосов
/ 21 июня 2019

Я читаю файл журнала доступа и конвертирую его в формат JSON.Я хочу хранить данные в Hbase только одна строка, это вставить, как это повторить?как решить эту проблему в python ниже мой код:

import happybase
import time
import datetime
import socket
import json
 import random

 from thriftpy2.transport import TTransportException
 connection = happybase.Connection('localhost')
 connection.open()
 print(connection.tables())
table = connection.table('testlog')
print(table.scan())

 def parse_log_line(line):
strptime = datetime.datetime.strptime
hostname = socket.gethostname()
time = line.split(' ')[3][1::]
entry = {}
entry['datetime'] = strptime(
    time, "%d/%b/%Y:%H:%M:%S").strftime("%Y-%m-%d %H:%M")
entry['source'] = "{}".format(hostname)
entry['type'] = "www_access"
entry['log'] = "'{}'".format(line.rstrip())
#seed(1)
# print(entry)
return entry

# return entry


 def show_entry(entry):
  temp = ",".join([
    entry['datetime'],
    entry['source'],
    entry['type'],
    entry['log']
  ])
log_entry = {'log': entry}
temp = json.dumps(log_entry)
# print(temp)
# print("{}".format(temp))
 print(entry['datetime'])
 b = table
 b.put(entry,{'datetime:col1':entry['datetime'],
                       'source:col2':entry['source'],
                        'type:col3':entry['type'],
                      'log:col4':entry['log']
                       })
 b.send()
print(entry['datetime']) //shows the all data
return temp


  def follow(syslog_file):
  # pubsub=happybase.Connection('localhost')

   while True:
    line = syslog_file.readline()

    # print(line)
    if not line:
        time.sleep(0.1)
        continue

    else:
        entry = parse_log_line(line)

        # print(entry)
        if not entry:
            continue
        json_entry = show_entry(entry)
       f = open("/Users/evioxtech/Downloads/access.log","r")

      follow(f)

только одна запись сделана в hbase, как вставить одну за другой данные, которые я использую для печати happybase (запись ['datetime']) показываетвсе данные

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...