forked from yokawasa/azure-functions-python-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
36 lines (28 loc) · 1.02 KB
/
__init__.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
import logging
import azure.functions as func
import json
def _rot13(c):
if 'A' <= c and c <= 'Z':
return chr((ord(c) - ord('A') + 13) % 26 + ord('A'))
if 'a' <= c and c <= 'z':
return chr((ord(c) - ord('a') + 13) % 26 + ord('a'))
return c
def process_rot13(s):
g = (_rot13(c) for c in s)
return ''.join(g)
def main(docs: func.DocumentList, outdoc: func.Out[func.Document]) -> str:
newdocs = func.DocumentList()
for doc in docs:
logging.info(doc.to_json())
## Process Something
clear_text = doc["text"]
encrypted_text= process_rot13(clear_text)
## Create a new doc (type:Dict)
newdoc_dict = {
"name": doc["name"],
"text": encrypted_text
}
## Append the new doc to DocumentList for output
newdocs.append(func.Document.from_dict(newdoc_dict))
## Set the DocumentList to outdoc to store into CosmosDB using CosmosDB output binding
outdoc.set(newdocs)