2024-07-19 00:04:51 +00:00
|
|
|
import pandas as pd
|
|
|
|
import datetime
|
|
|
|
|
2024-10-03 01:53:37 +00:00
|
|
|
import os
|
|
|
|
from pathlib import Path
|
2024-07-19 00:04:51 +00:00
|
|
|
|
2024-10-03 01:53:37 +00:00
|
|
|
from utils.documents_to_database import documents_to_database
|
2024-07-19 00:04:51 +00:00
|
|
|
|
2024-10-03 01:53:37 +00:00
|
|
|
#%% In[ ]:
|
|
|
|
# Get the current file's directory
|
|
|
|
try:
|
|
|
|
# This will work when running as a script
|
|
|
|
script_dir = Path(__file__).parent.parent
|
|
|
|
except NameError:
|
|
|
|
# This will work in interactive environments
|
|
|
|
script_dir = Path().absolute()
|
|
|
|
|
|
|
|
project_root = script_dir
|
|
|
|
linkedin_data_path = os.path.join(project_root, 'import_data', 'data', 'LinkedIn', 'comments', 'Comments.csv')
|
|
|
|
|
|
|
|
#%% In[ ]:
|
|
|
|
raw_comments_csv = pd.read_csv(linkedin_data_path,
|
|
|
|
escapechar='\\',
|
|
|
|
skipinitialspace=True)
|
|
|
|
raw_comments_csv['MessageFix'] = raw_comments_csv['Message'].str.replace(r'[\r\n\t]+', ' ', regex=True)
|
|
|
|
raw_comments_csv = raw_comments_csv.drop(columns=['Message'])
|
2024-07-19 01:54:15 +00:00
|
|
|
raw_comments = raw_comments_csv[(raw_comments_csv['MessageFix'] != "")].drop_duplicates()
|
2024-07-19 00:04:51 +00:00
|
|
|
|
2024-10-03 01:53:37 +00:00
|
|
|
#%% In[ ]:
|
2024-07-19 00:04:51 +00:00
|
|
|
raw_comments['index'] = "rs_linkedin_comments"
|
|
|
|
raw_comments['type'] = "comments"
|
|
|
|
raw_comments['network'] = "LinkedIn"
|
|
|
|
raw_comments['chemin'] = linkedin_data_path
|
|
|
|
|
2024-10-03 01:53:37 +00:00
|
|
|
#%% In[ ]:
|
|
|
|
raw_comments["creation_timestamp"] = raw_comments["Date"].apply(
|
|
|
|
lambda x: int(datetime.datetime.fromisoformat(x).timestamp())
|
|
|
|
)
|
2024-07-19 00:04:51 +00:00
|
|
|
del raw_comments["Date"]
|
|
|
|
|
2024-10-03 01:53:37 +00:00
|
|
|
#%% In[ ]:
|
2024-07-19 01:54:15 +00:00
|
|
|
raw_comments.rename(columns={"Link": "uri", "MessageFix": "texte"}, inplace=True)
|
2024-07-19 00:04:51 +00:00
|
|
|
|
2024-10-03 01:53:37 +00:00
|
|
|
#%% In[ ]:
|
2024-07-19 00:04:51 +00:00
|
|
|
raw_comments["chemin"] = linkedin_data_path
|
|
|
|
|
2024-10-03 01:53:37 +00:00
|
|
|
#%% In[ ]:
|
2024-07-19 00:04:51 +00:00
|
|
|
raw_comments.fillna(value="", inplace=True)
|
|
|
|
|
2024-10-03 01:53:37 +00:00
|
|
|
#%% In[ ]:
|
|
|
|
raw_comments.drop_duplicates(subset=['texte', 'creation_timestamp'], inplace=True)
|
2024-07-19 00:04:51 +00:00
|
|
|
|
2024-10-03 01:53:37 +00:00
|
|
|
#%% In[ ]:
|
2024-07-19 00:04:51 +00:00
|
|
|
# Filter empty texte
|
|
|
|
raw_comments = raw_comments[~raw_comments['texte'].str.strip('\n').str.strip().eq('')]
|
|
|
|
|
2024-10-03 01:53:37 +00:00
|
|
|
#%% In[ ]:
|
2024-07-19 00:04:51 +00:00
|
|
|
documents_to_database(raw_comments)
|