Commit 17f6cf8b authored by Bogdan's avatar Bogdan

Working Schema & Upload

parent 776d16a1
from _add_use_case_scripts.requestPost import postLayersToSwagger, postTableToSwagger import network_constants as nc
from security.token_manager import TokenManager
import requests
def add_table(use_case: str, table_name: str): def add_table(use_case: str, table_name: str):
''' '''
...@@ -32,20 +35,19 @@ def add_table(use_case: str, table_name: str): ...@@ -32,20 +35,19 @@ def add_table(use_case: str, table_name: str):
"mappings": columns "mappings": columns
} }
postTableToSwagger(use_case,table) url = f"https://articonf1.itec.aau.at:30420/api/use-cases/{use_case}/tables"
jwt = TokenManager.getInstance().getToken()
response = requests.post(
url,
verify=False,
proxies = { "http":None, "https":None },
headers = { "Authorization": f"Bearer {jwt}"},
json = table
)
# { #EXAMPLE JSON print(url+": "+str(response.status_code))
# "id":"larjmz",
# "user_id":"R3V0LV3Rocelot",
# "title":"Outrage As Robinhood CEO Confesses To Elon Musk: DTCC Shut Down Stocks In Gamestop; AMC Surge",
# "content":"",
# "permalink":"/r/news/comments/larjmz/outrage_as_robinhood_ceo_confesses_to_elon_musk/",
# "upvotes":57,
# "percentage_upvoted":0.86,
# "n_comments":19,
# "subreddit":"news"
# }
def add_layers(use_case:str, table_name: str): def add_layers(use_case:str, table_name: str):
layers = [ layers = [
{ {
...@@ -146,7 +148,20 @@ def add_layers(use_case:str, table_name: str): ...@@ -146,7 +148,20 @@ def add_layers(use_case:str, table_name: str):
} }
] ]
postLayersToSwagger(use_case,layers) jwt = TokenManager.getInstance().getToken()
for layer in layers:
url = f"https://articonf1.itec.aau.at:30420/api/layers"
response = requests.post(
url,
verify=False,
proxies = { "http":None, "https":None },
headers = { "Authorization": f"Bearer {jwt}"},
json = layer
)
print(url+": "+str(response.status_code))
def main(use_case: str): def main(use_case: str):
print("reddit") print("reddit")
......
[{"id": "lat2of", "user_id": "JamesKBoyd", "title": "California man falls to his death while canyoneering at Death Valley", "content": "", "permalink": "/r/news/comments/lat2of/california_man_falls_to_his_death_while/", "upvotes": 0, "percentage_upvoted": 0.5, "n_comments": 3, "subreddit": "news"}, {"id": "lasy7g", "user_id": "watercolornightmares", "title": "How Rich Hospitals Profit From Patients in Car Crashes", "content": "", "permalink": "/r/news/comments/lasy7g/how_rich_hospitals_profit_from_patients_in_car/", "upvotes": 2, "percentage_upvoted": 0.57, "n_comments": 3, "subreddit": "news"}, {"id": "lasrjq", "user_id": "wilmots1", "title": "Moscow court hears case for jailing Putin critic Navalny", "content": "", "permalink": "/r/news/comments/lasrjq/moscow_court_hears_case_for_jailing_putin_critic/", "upvotes": 9, "percentage_upvoted": 0.84, "n_comments": 0, "subreddit": "news"}]
\ No newline at end of file
...@@ -5,18 +5,21 @@ import sys ...@@ -5,18 +5,21 @@ import sys
import os import os
import json import json
modules_path = '../../../modules/' import urllib3
if os.path.exists(modules_path): urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
sys.path.insert(1, modules_path)
#import network_constants as nc # modules_path = '../../../modules/'
#from security.token_manager import TokenManager # if os.path.exists(modules_path):
# sys.path.insert(1, modules_path)
# import network_constants as nc
# from security.token_manager import TokenManager
def send_transaction_to_rest_gateway(transaction: dict): def send_transaction_to_rest_gateway(transaction: dict):
# token from Rest Gateway to authorize # token from Rest Gateway to authorize
#JWT_TOKEN = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6InJlZ3VsYXJAaXRlYy5hYXUuYXQiLCJjcmVhdGVkX2F0IjoiMjAyMC0xMC0wNiAwOTowNzoyMy44MjEyOTciLCJ2YWxpZF91bnRpbCI6IjIwMjAtMTAtMDcgMDk6MDc6MjMuODIxMjk3In0.orqTjn-3J4qMM0kpreWVPkwUEtUcgoqo6wsUFxKCrwg' JWT_TOKEN = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6InJlZ3VsYXJAaXRlYy5hYXUuYXQiLCJjcmVhdGVkX2F0IjoiMjAyMS0wMi0wOCAxMzo0NzoxOC40NzUxMjEiLCJ2YWxpZF91bnRpbCI6IjIwMjEtMDItMDkgMTM6NDc6MTguNDc1MTIxIn0.DWY9c0X2XQJDz0Ef35-k1IVY6GWf00ogaVOCeX8Irlo'
#JWT_TOKEN = TokenManager.getInstance().getToken()
res = requests.post( res = requests.post(
url = 'https://articonf1.itec.aau.at:30401/api/trace', url = 'https://articonf1.itec.aau.at:30401/api/trace',
json = transaction, json = transaction,
...@@ -40,7 +43,6 @@ if __name__ == '__main__': ...@@ -40,7 +43,6 @@ if __name__ == '__main__':
summ = 0 summ = 0
for obj_dict in json_data_list: for obj_dict in json_data_list:
print ("a")
transaction = {} transaction = {}
transaction['ApplicationType'] = 'reddit' transaction['ApplicationType'] = 'reddit'
transaction['docType'] = 'reddit' transaction['docType'] = 'reddit'
...@@ -52,7 +54,7 @@ if __name__ == '__main__': ...@@ -52,7 +54,7 @@ if __name__ == '__main__':
send_transaction_to_rest_gateway(transaction) send_transaction_to_rest_gateway(transaction)
summ+=1 summ+=1
if (summ % 100 == 0 ): if (summ % 1000 == 0 ):
print ("Uploaded " + str(summ) + " transactions.") print ("Uploaded " + str(summ) + " transactions.")
print ("TOTAL Uploaded " + str(summ) + " transactions.") print ("TOTAL Uploaded " + str(summ) + " transactions.")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment