Skip to content

Commit c0b6e30

Browse files
committed
mod19: update tmpl, add maker script
1 parent 244aa64 commit c0b6e30

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ If your original app users does *not* have a user interface, i.e., mobile backen
304304

305305
## Accessing legacy services in second generation
306306

307-
Many legacy App Engine first generation platform (Python 2, Java 8, PHP 5, and Go 1.11 & older) services are available ([as of Sep 2021](https://twitter.com/googledevs/status/1445916786755571712) for second generation runtimes (Python 3, Java 11, PHP 7, and Go 1.12 & newer) in a public preview. There are no videos or codelabs yet, however the Module 1 Flask migration using App Engine `ndb` [Python 2 sample ](/mod1-flask) is available in [Python 3](/mod1b-flask) if you have access. Similarly, Python 3 editions are also available for Modules 7 and 12 which add usage of App Engine `taskqueue` and `memcache`, respectively. Also see the [documentation on accessing bundled services from Python 3](https://cloud.google.com/appengine/docs/standard/python3/services/access).
307+
Many legacy App Engine first generation platform (Python 2, Java 8, PHP 5, and Go 1.11 & older) services are available ([as of Sep 2021](https://twitter.com/googledevs/status/1445916786755571712) for second generation runtimes (Python 3, Java 11/17, PHP 7/8, and Go 1.12 & newer) in a public preview. There are no videos or codelabs yet, however the Module 1 Flask migration using App Engine `ndb` [Python 2 sample](/mod1-flask) is available in [Python 3](/mod1b-flask) if you have access. Similarly, Python 3 editions are also available for Modules 7 and 12 which add usage of App Engine `taskqueue` and `memcache`, respectively. Also see the [documentation on accessing bundled services from Python 3](https://cloud.google.com/appengine/docs/standard/python3/services/access).
308308

309309

310310
## References

Diff for: mod19-pubsub/maker.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from __future__ import print_function
16+
import google.auth
17+
from google.api_core import exceptions
18+
from google.cloud import pubsub
19+
20+
_, PROJECT_ID = google.auth.default()
21+
TOPIC = 'pullq'
22+
SBSCR = 'worker'
23+
ppc_client = pubsub.PublisherClient()
24+
psc_client = pubsub.SubscriberClient()
25+
TOP_PATH = ppc_client.topic_path(PROJECT_ID, TOPIC)
26+
SUB_PATH = psc_client.subscription_path(PROJECT_ID, SBSCR)
27+
28+
def make_top():
29+
try:
30+
top = ppc_client.create_topic(name=TOP_PATH)
31+
print('Created topic %r (%s)' % (TOPIC, top.name))
32+
except exceptions.AlreadyExists:
33+
print('Topic %r already exists at %r' % (TOPIC, TOP_PATH))
34+
35+
def make_sub():
36+
with psc_client:
37+
try:
38+
sub = psc_client.create_subscription(name=SUB_PATH, topic=TOP_PATH)
39+
print('Subscription created %r (%s)' % (SBSCR, sub.name))
40+
except exceptions.AlreadyExists:
41+
print('Subscription %r already exists at %r' % (SBSCR, SUB_PATH))
42+
43+
make_top()
44+
make_sub()

Diff for: mod19-pubsub/templates/index.html

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ <h1>VisitMe example</h1>
99
<h3>Top {{ limit }} visitors</h3>
1010
<table border=1 cellspacing=0 cellpadding=2>
1111
<tr><th>Visitor</th><th>Visits</th></tr>
12-
{% for count in counts %}
13-
<tr><td>{{ count.visitor|e }}</td><td align="center">{{ count.counter }}</td></tr>
14-
{% endfor %}
12+
{% if counts %}
13+
{% for count in counts %}
14+
<tr><td>{{ count.visitor|e }}</td><td align="center">{{ count.counter }}</td></tr>
15+
{% endfor %}
16+
{% else %}
17+
<tr><td colspan=2 align="center"><i>(none yet; visit the <code>/log</code> endpoint)</i></td></tr>
18+
{% endif %}
1519
</table>
1620

1721
<h3>Last {{ limit }} visits</h3>

0 commit comments

Comments
 (0)