2023-02-03 15:13:57 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
"""
|
|
|
|
The Twitter Feeder Importer Module
|
|
|
|
================
|
|
|
|
|
|
|
|
Process Twitter JSON
|
|
|
|
|
|
|
|
"""
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import datetime
|
|
|
|
|
|
|
|
sys.path.append(os.environ['AIL_BIN'])
|
|
|
|
##################################
|
|
|
|
# Import Project packages
|
|
|
|
##################################
|
|
|
|
from importer.feeders.Default import DefaultFeeder
|
|
|
|
from lib.objects.Usernames import Username
|
2023-08-28 14:29:38 +00:00
|
|
|
from lib.objects.Items import Item
|
2023-02-03 15:13:57 +00:00
|
|
|
|
|
|
|
class TwitterFeeder(DefaultFeeder):
|
|
|
|
|
|
|
|
def __init__(self, json_data):
|
|
|
|
super().__init__(json_data)
|
|
|
|
self.name = 'twitter'
|
|
|
|
|
|
|
|
# define item id
|
|
|
|
def get_item_id(self):
|
|
|
|
# TODO twitter timestamp message date
|
|
|
|
date = datetime.date.today().strftime("%Y/%m/%d")
|
|
|
|
item_id = str(self.json_data['meta']['twitter:tweet_id'])
|
|
|
|
item_id = os.path.join('twitter', date, item_id)
|
|
|
|
self.item_id = f'{item_id}.gz'
|
|
|
|
return self.item_id
|
|
|
|
|
|
|
|
def process_meta(self):
|
|
|
|
'''
|
|
|
|
Process JSON meta field.
|
|
|
|
'''
|
|
|
|
# tweet_id = str(self.json_data['meta']['twitter:tweet_id'])
|
|
|
|
# item_basic.add_map_obj_id_item_id(tweet_id, item_id, 'twitter_id') ############################################
|
2023-08-28 14:29:38 +00:00
|
|
|
item = Item(self.item_id)
|
|
|
|
date = item.get_date()
|
2023-02-03 15:13:57 +00:00
|
|
|
user = str(self.json_data['meta']['twitter:id'])
|
|
|
|
username = Username(user, 'twitter')
|
2023-08-28 14:29:38 +00:00
|
|
|
username.add(date, item)
|
2023-02-03 15:13:57 +00:00
|
|
|
return None
|