This repository has been archived by the owner on Dec 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inject-dynamo.py
61 lines (52 loc) · 1.94 KB
/
inject-dynamo.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
import boto3
import json
import os
import base64
import time
AWS_ACCESS_ID = os.environ["AWS_ACCESS_ID"]
AWS_ACCESS_KEY = os.environ["AWS_ACCESS_KEY"]
client = boto3.Session(AWS_ACCESS_ID, AWS_ACCESS_KEY,region_name="ap-southeast-2").client("dynamodb")
def load_json(file):
with open(file) as f:
contents = json.load(f)["data"]
return contents
def upload_recipe(json_obj):
#json_obj = json.loads(json_obj)
try:
if "event" not in json_obj.keys():
return
elif json_obj["category"] == "Work Orders":
return
elif any(res in json_obj["output"]["name"].lower() for res in ["covenant", "syndicate", "marauder"]):
return
except Exception as e:
return
payload = {
'tradeskill' : {"S": json_obj["tradeskill"]},
'recipelevel' : {"N": str(json_obj["recipeLevel"])},
'ingredients' : {"B": base64.b64encode(bytes(str(json_obj["ingredients"]),'utf-8'))},
'name' : {"S": json_obj["id"]},
'itemName' : {"S": json_obj['output']['name']},
'event' : {"B": base64.b64encode(bytes(str(json_obj["event"]),'utf-8'))}
}
response = client.put_item(
TableName='CraftingRecipes',
Item=payload
)
print(payload)
print(response)
return response
def upload_all_recipe(path):
for e in os.listdir(path):
time.sleep(0.10)
if e.endswith(".json"):
print(e)
try:
upload_recipe(load_json(path+'/'+e))
except Exception as exp:
print(e+'\n'+str(exp)+'\n\n')
if __name__ == "__main__":
#print(load_json("./nwdb.info/db/recipe/Woodworker_ClothWeaveT3.json"))
#upload_recipe(load_json("./nwdb.info/db/recipe/Woodworker_ClothWeaveT3.json"))
#upload_all_recipe('/Users/ljs/Projects/new-world-buddy/nwdb.info/db/recipe/json')
upload_all_recipe('/Users/ljs/Projects/new-world-buddy/nwdb.info/db/recipe/json')