You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -54,6 +56,102 @@ After you initialize a project, you need to create functions. This project requi
54
56
-`negotiate`: Allows a client to get an access token.
55
57
-`broadcast`: Uses a time trigger to periodically broadcast messages to all clients.
56
58
59
+
When you run the `func new` command from the root directory of the project, the Azure Functions Core Tools appends the function code in the `function_app.py` file. You'll edit the parameters ad content as necessary by replacing the default code with the app code.
60
+
61
+
### Create the index function
62
+
63
+
You can use this sample function as a template for your own functions.
64
+
65
+
Open the file `function_app.py`. This file will contain your functions. First, modify the file to include the neccessary import statements, and define global variables that we will be using in the following functions.
66
+
67
+
```python
68
+
import azure.functions as func
69
+
import os
70
+
import requests
71
+
import json
72
+
73
+
app = func.FunctionApp()
74
+
75
+
etag =''
76
+
start_count =0
77
+
```
78
+
79
+
2. Add the function `index` by adding the following code
res = requests.get('https://api.github.com/repos/azure/azure-functions-python-worker', headers=headers)
117
+
if res.headers.get('ETag'):
118
+
etag = res.headers.get('ETag')
119
+
120
+
if res.status_code ==200:
121
+
jres = res.json()
122
+
start_count = jres['stargazers_count']
123
+
124
+
signalRMessages.set(json.dumps({
125
+
'target': 'newMessage',
126
+
'arguments': [ 'Current star count of https://api.github.com/repos/azure/azure-functions-python-worker is: '+str(start_count) ]
127
+
}))
128
+
```
129
+
130
+
This function uses a time trigger to periodically broadcast messages to all clients.
131
+
::: zone-end
132
+
133
+
::: zone pivot="python-mode-configuration"
134
+
## Create the Azure Function project
135
+
136
+
Create a local Azure Function project.
137
+
138
+
1. From a command line, create a directory for your project.
139
+
1. Change to the project directory.
140
+
1. Use the Azure Functions `func init` command to initialize your function project.
141
+
142
+
```bash
143
+
# Initialize a function project
144
+
func init --worker-runtime python --model v1
145
+
```
146
+
147
+
## Create the functions
148
+
149
+
After you initialize a project, you need to create functions. This project requires three functions:
150
+
151
+
-`index`: Hosts a web page for a client.
152
+
-`negotiate`: Allows a client to get an access token.
153
+
-`broadcast`: Uses a time trigger to periodically broadcast messages to all clients.
154
+
57
155
When you run the `func new` command from the root directory of the project, the Azure Functions Core Tools creates default function source files and stores them in a folder named after the function. You'll edit the files as necessary replacing the default code with the app code.
58
156
59
157
### Create the index function
@@ -212,6 +310,7 @@ You can use this sample function as a template for your own functions.
212
310
'arguments': [ 'Current star count of https://github.com/Azure/azure-signalr is: '+str(start_count) ]
0 commit comments