-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathminerva_injection.py
51 lines (35 loc) · 1.23 KB
/
minerva_injection.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
import urllib.request
import json
import orator
import re
import boto3
import sys
import requests
from bs4 import BeautifulSoup
session = boto3.session.Session(profile_name="tower")
s3 = session.resource("s3")
exhibit_key = sys.argv[1] + "exhibit.json"
index_key = sys.argv[1] + "index.html"
bucket = "htan-project-tower-bucket"
exhibit_s3object = s3.Object(bucket, exhibit_key)
exhibit = exhibit_s3object.get()["Body"].read()
exhibit = json.loads(exhibit.decode("UTF-8"))
index_s3object = s3.Object(bucket, index_key)
index = index_s3object.get()["Body"].read().decode("UTF-8")
# print(index)
synid = re.match(r".+(syn\d+).+", exhibit_key).group(1)
oration = orator.orate_miti(synid)
print(oration)
oration_ready = (
oration.replace("\n", "\\n")
.replace("False", "false")
.replace("'", '"')
.replace("_", "\_")
)
new_exhibit = exhibit
new_exhibit["Header"] = oration_ready
new_index = re.sub(r"exhibit: \{.+\}", "exhibit: " + str(new_exhibit), index)
# exhibit_s3object = s3.Object(bucket, sys.argv[1] + "exhibit2.json")
# index_s3object = s3.Object(bucket, sys.argv[1] + "index2.html")
exhibit_s3object.put(Body=(bytes(json.dumps(new_exhibit).encode("UTF-8"))))
index_s3object.put(Body=(bytes(new_index.encode("UTF-8"))))