-
Notifications
You must be signed in to change notification settings - Fork 0
/
consumer.py
executable file
·75 lines (71 loc) · 2.62 KB
/
consumer.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
#!/usr/bin/env python3
from datetime import datetime
import json
import sys
from user_office import UserOffice
from kafka import KafkaConsumer
from streaming_data_types import deserialise_wrdn
userOffice = UserOffice()
userOffice.login("[email protected]", "Test1234!")
consumer = KafkaConsumer(
"command_channel",
group_id="group1",
#bootstrap_servers=["172.17.0.31:9092"],
bootstrap_servers=["dmsc-kafka01.cslab.esss.lu.se:9092"],
auto_offset_reset="earliest",
)
try:
for message in consumer:
data_type = message.value[4:8]
if data_type == b"wrdn":
entry = deserialise_wrdn(message.value)
if entry.error_encountered:
continue
# print(entry)
proposalId = json.loads(entry.metadata)["proposal"]
proposalId = 169
proposal = userOffice.get_proposal(proposalId)
# print(proposal)
principalInvestigator = (
proposal["proposer"]["firstname"].replace("-user", "")
+ " "
+ proposal["proposer"]["lastname"]
)
email = principalInvestigator.replace(" ", "").lower() + "@ess.eu"
instrument = proposal["instrument"]["name"]
sourceFolder = (
"/nfs/groups/beamlines/"
+ instrument
+ "/"
+ proposal["shortCode"]
+ "/"
+ entry.file_name
)
dataset = {
"datasetName": "Dataset from FileWriter",
"description": "Dataset ingested from FileWriter",
"principalInvestigator": principalInvestigator,
"creationLocation": instrument,
"scientificMetadata": json.loads(entry.metadata),
"owner": principalInvestigator,
"contactEmail": email,
"sourceFolder": entry.file_name,
"creationTime": datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.000Z"),
"type": "raw",
"ownerGroup": "ess",
"accessGroups": ["loki", "odin"],
"techniques": [
{
"pid": "random-alphanumerical-string",
"name": "Absorption something or the other",
}
],
"instrumentId": proposal["instrument"]["id"],
"proposalId": proposal["shortCode"],
}
print(dataset)
# name = entry.source_name
# value = entry.value
# print(f"{name}: {value}")
except KeyboardInterrupt:
sys.exit()