-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
129 lines (124 loc) · 4.9 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
from numpy import empty
from pendulum import datetime
from data_extract.yfinanceExtractor import yfinanceExtractor
from data_extract.yahooFinNewsExtractor import yahooFinNewsExtractor
from data_extract.yfinanceExtractor import yfinanceExtractor
from data_load.bigQueryAPI import bigQueryDB
from data_extract.TelegramExtractor import TelegramExtractor
from data_extract.SGXDataExtractor import SGXDataExtractor
from data_extract.SBRExtractor import SBRExtractor
from data_transform.generateHeatListFromQuery import GenerateHeatlistsFromQuery
from data_transform.yfinanceTransform import yfinanceTransform
from data_transform.FinBertAPI import FinBERT
from matplotlib import ticker
from datetime import datetime as dt
import time
import pandas as pd
import json
if __name__ == '__main__':
start_time = time.time()
# ---- Initalisation Telegram Session ---- #
Telegram_layer = TelegramExtractor()
Telegram_layer.init_tele_session()
# CODE BELOW FOR UNIT TESTING PURPOSES. CODE IS TO BE TRIGGERED FROM MAIN_DAG.PY
# ---- Test SGX Data Extraction ---- #
# sgx_data_extractor_layer = SGXDataExtractor()
# sgx_data_extractor_layer.load_SGX_data_from_source()
#
# ---- Test SBR Data Extraction ---- #
# sbr_data_extraction_layer = SBRExtractor()
# sbr_data_extraction_layer.load_SBR_data_from_source(
# start_date="01-02-2022", end_date="10-03-2022")
#
# ---- Test Telegram Data Extraction ---- #
# tele_data_extractor_layer = TelegramExtractor()
#
# Extracts all data
# tele_data_extractor_layer.extract_telegram_messages()
#
# Extracts from start date to end date
# tele_data_extractor_layer.extract_telegram_messages(start_date="01-02-2022", end_date="10-02-2022")
#
# ---- Test YahooFinNews Extraction and Pipeline ---- #
# tickerNews = yahooFinNewsExtractor().getSGXTickerNews()
# yahoo_fin_pipeline_layer = yahooFinNewsPipeline()
# formattedData = yahoo_fin_pipeline_layer.tickerNewsFormat(
# tickerNews, dt(2020, 5, 17))
# yahoo_fin_pipeline_layer.newsToFirestore()
#
# ---- Test FireStore Pipeline ---- #
# FireStore_layer = FirestorePipeline()
# FireStore_layer.execute_pipeline(
# start_date="20-02-2022", end_date="22-02-2022")
#
# ---- Test GBQ Pipeline ---- #
# gbq_layer = bigQueryDB()
# df = pd.DataFrame(
# {
# 'my_string': ['a', 'b', 'c'],
# 'my_int64': [1, 2, 3],
# 'my_float64': [4.0, 5.0, 6.0],
# 'my_timestamp': [
# pd.Timestamp("1998-09-04T16:03:14"),
# pd.Timestamp("2010-09-13T12:03:45"),
# pd.Timestamp("2015-10-02T16:00:00")
# ],
# }
# )
#
# Test Table Creation
# print(gbq_layer.gbqCreateNewTable(df, "test.test01"))
#
# Test Table Append
# print(gbq_layer.gbqAppend(df, "test", "test12"))
#
# Test Table Replace
# print(gbq_layer.gbqReplace(df, "test", "test12"))
#
# Test Query Using SQL
# print(gbq_layer.getDataQuery("SELECT my_string FROM test.test02"))
#
# Test Query Using FieldName
# print(gbq_layer.getDataFields("test.test02","my_string","my_float64"))
#
# Test Schema Extraction
# schema = gbq_layer.updateTableSchema(["SGX.Tickers",
# "yfinance.earnings_and_revenue",
# "yfinance.stock_info"
# ])
# print(schema)
#
# ---- Test yFinance Extract ---- #
# gbq_layer = bigQueryDB()
# sgx_data = bigQueryDB().getDataFields("SGX.Tickers").head()
# yfinance_data_to_upload = yfinanceExtractor(sgx_data).yfinanceQuery()
#
# ---- Test yFinance Transform ---- #
# tableSchemaUrl = "utils/bigQuerySchema.json"
# with open(tableSchemaUrl, 'r') as schemaFile:
# tableSchema = json.load(schemaFile)
# yfinanceTransform_layer = yfinanceTransform(yfinance_data_to_upload)
# yfinanceTransform_layer.transformData()
#
# ---- Test yFinance Upload ---- #
# gbq_layer.gbqAppend(yfinance_data_to_upload, "yfinance.earnings_and_revenue",
# tableSchema["yfinance.earnings_and_revenue"])
#
# ---- Test Heatlist Generation ---- #
# ind_data = yfinance_data_to_upload["stock_industry"]
# print(ind_data)
# gen_heat_list = GenerateHeatlistsFromQuery(sgx_data, ind_data)
#
# ---- Test SGXDataExtractor---- #
# sgx_layer = SGXDataExtractor()
# sgx_data = sgx_layer.get_SGX_data()
# gbq_data = sgx_layer.get_SGXData_from_GBQ()
# update = sgx_layer.update_ticker_status(sgx_data, gbq_data)
# print(update)
# update.to_csv("update.csv", index=False)
#
# ---- Test FinBert---- #
# df = pd.read_csv("csv_store/industry_new.csv")
# fb_layer = FinBERT()
# fb_layer.FinBert_pipeline(df["industry"])
print("--- %s seconds ---" % (time.time() - start_time))