Skip to content

Commit dc50ff5

Browse files
chenqichenqi
authored andcommitted
misc update
1 parent d77591f commit dc50ff5

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

PageSpeedInsights/job.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
PROJECT_ID = os.getenv("GCP_PROJECT_ID")
88
TOPIC_NAME = "psi-single"
99

10+
URL_DICT = ["https://m.ctrip.com/webapp/flight/schedule/detail.html"]
11+
1012
def run(event, context):
1113
publisher = pubsub_v1.PublisherClient()
1214
topic = publisher.topic_path(PROJECT_ID, TOPIC_NAME)
13-
data = b'https://m.ctrip.com/webapp/flight/schedule/detail.html'
14-
publisher.publish(topic, data)
15+
for url in URL_DICT:
16+
data = url.encode('utf-8')
17+
publisher.publish(topic, data)
1518
return 'OK'
1619

1720
def test_job():

PageSpeedInsights/psi.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# -*- coding: utf-8 -*-
33
'''PageSpeed Insights Single + Google Cloud Functions'''
44
import os
5+
import base64
56
import requests
67

78
# Access Token, generated from GCP Console Credentials page.
@@ -27,22 +28,19 @@ def run(url):
2728
print(response.json())
2829
except requests.RequestException as _e:
2930
print(_e)
30-
return ('OK', 200)
31+
return 'OK'
3132

3233

3334
def run_pubsub(event, context):
34-
import base64
3535
pubsub_message = base64.urlsafe_b64decode(event['data']).decode('utf-8')
36-
run(pubsub_message)
37-
return 'OK'
36+
return run(pubsub_message)
3837

3938

4039
def test_run_http(test_url):
4140
run(test_url)
4241

4342

4443
def test_run_pubsub(test_url):
45-
import base64
4644
event = {"data": base64.urlsafe_b64encode(test_url.encode('utf-8'))}
4745
context = None
4846
run_pubsub(event, context)

PageSpeedInsights/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# Function dependencies, for example:
1+
# Function dependencies
22
requests==2.21.0
33
google-cloud-pubsub==0.40.0

0 commit comments

Comments
 (0)