-
Notifications
You must be signed in to change notification settings - Fork 0
/
UploadDataToES.py
50 lines (35 loc) · 1.27 KB
/
UploadDataToES.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
import os
from google_auth_oauthlib.flow import InstalledAppFlow
import pickle
from datetime import datetime
from requests import api
from apiclient.discovery import build
from tqdm import tqdm
import requests
import json
import re
import time
import requests
Api_key = open("apikey.txt", 'r')
Api_key = str(Api_key.read())
import ast
# open finished labels json file
labels_file = open("finished-labels.json", "r")
labels_file_dump = labels_file.read()
# interpret the file into an array of dicts using ast.literal_eval
labels_arr = ast.literal_eval(labels_file_dump)
for i, video in tqdm(enumerate(labels_arr)):
# print(video)
# print(video["image"][video["image"].rfind("/") + 1:video["image"].rfind(".jpg")])
video["id"] = video["image"][video["image"].rfind("/") + 1:video["image"].rfind(".jpg")]
video["hq_default"] = "https://img.youtube.com/vi/" + video["id"] + "/hqdefault.jpg"
print(video)
headers = {
"Authorization" : "Basic ",
'Content-Type': 'application/json'
}
response = requests.post("https://search-mth420-project2-d6zohqo2oxsc5gsn23f5aavdkm.us-west-2.es.amazonaws.com/labels/_doc", data=json.dumps(video),headers=headers)
print("\n\n")
# print(response.status_code)
# print(response.content)
# curl -X POST -u