2023-02-03 16:13:57 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
"""
|
|
|
|
The Default JSON Feeder Importer Module
|
|
|
|
================
|
|
|
|
|
|
|
|
Process Feeder Json (example: Twitter feeder)
|
|
|
|
|
|
|
|
"""
|
|
|
|
import os
|
|
|
|
import datetime
|
2023-10-05 16:24:28 +02:00
|
|
|
import sys
|
2023-02-03 16:13:57 +01:00
|
|
|
import uuid
|
|
|
|
|
2023-10-05 16:24:28 +02:00
|
|
|
sys.path.append(os.environ['AIL_BIN'])
|
|
|
|
##################################
|
|
|
|
# Import Project packages
|
|
|
|
##################################
|
|
|
|
from lib.objects import ail_objects
|
|
|
|
|
2023-02-03 16:13:57 +01:00
|
|
|
class DefaultFeeder:
|
|
|
|
"""Default Feeder"""
|
|
|
|
|
|
|
|
def __init__(self, json_data):
|
|
|
|
self.json_data = json_data
|
2023-10-05 16:24:28 +02:00
|
|
|
self.obj = None
|
2023-02-03 16:13:57 +01:00
|
|
|
self.name = None
|
|
|
|
|
|
|
|
def get_name(self):
|
|
|
|
"""
|
|
|
|
Return feeder name. first part of the item_id and display in the UI
|
|
|
|
"""
|
|
|
|
if not self.name:
|
2023-08-29 13:50:16 +02:00
|
|
|
name = self.get_source()
|
|
|
|
else:
|
|
|
|
name = self.name
|
|
|
|
if not name:
|
|
|
|
name = 'default'
|
|
|
|
return name
|
2023-02-03 16:13:57 +01:00
|
|
|
|
|
|
|
def get_source(self):
|
|
|
|
return self.json_data.get('source')
|
|
|
|
|
2024-04-25 14:18:22 +02:00
|
|
|
def get_date(self):
|
|
|
|
return datetime.date.today().strftime("%Y%m%d")
|
|
|
|
|
2024-06-06 15:05:40 +02:00
|
|
|
def get_feeder_timestamp(self):
|
|
|
|
timestamp = self.json_data.get('timestamp')
|
|
|
|
if timestamp:
|
|
|
|
return int(timestamp)
|
|
|
|
|
2023-02-03 16:13:57 +01:00
|
|
|
def get_json_data(self):
|
|
|
|
"""
|
|
|
|
Return the JSON data,
|
|
|
|
"""
|
|
|
|
return self.json_data
|
|
|
|
|
|
|
|
def get_json_meta(self):
|
|
|
|
return self.json_data.get('meta')
|
|
|
|
|
|
|
|
def get_uuid(self):
|
|
|
|
return self.json_data.get('source_uuid')
|
|
|
|
|
|
|
|
def get_default_encoding(self):
|
|
|
|
return self.json_data.get('default_encoding')
|
|
|
|
|
|
|
|
def get_gzip64_content(self):
|
|
|
|
"""
|
|
|
|
Return the base64 encoded gzip content,
|
|
|
|
"""
|
|
|
|
return self.json_data.get('data')
|
|
|
|
|
2023-11-15 14:12:50 +01:00
|
|
|
def get_obj_type(self):
|
2024-02-06 11:13:45 +01:00
|
|
|
meta = self.get_json_meta()
|
|
|
|
return meta.get('type', 'item')
|
2023-11-15 14:12:50 +01:00
|
|
|
|
2023-02-03 16:13:57 +01:00
|
|
|
## OVERWRITE ME ##
|
2023-10-05 16:24:28 +02:00
|
|
|
def get_obj(self):
|
2023-02-03 16:13:57 +01:00
|
|
|
"""
|
2023-10-05 16:24:28 +02:00
|
|
|
Return obj global id. define obj global id
|
|
|
|
Default == item object
|
2023-02-03 16:13:57 +01:00
|
|
|
"""
|
|
|
|
date = datetime.date.today().strftime("%Y/%m/%d")
|
2023-10-05 16:24:28 +02:00
|
|
|
obj_id = os.path.join(self.get_name(), date, str(uuid.uuid4()))
|
|
|
|
obj_id = f'{obj_id}.gz'
|
|
|
|
obj_id = f'item::{obj_id}'
|
|
|
|
self.obj = ail_objects.get_obj_from_global_id(obj_id)
|
|
|
|
return self.obj
|
2023-02-03 16:13:57 +01:00
|
|
|
|
|
|
|
## OVERWRITE ME ##
|
|
|
|
def process_meta(self):
|
|
|
|
"""
|
|
|
|
Process JSON meta filed.
|
|
|
|
"""
|
|
|
|
# meta = self.get_json_meta()
|
2023-11-24 15:05:19 +01:00
|
|
|
return set()
|