-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add new version of GCP reminder function
- Loading branch information
Showing
2 changed files
with
44 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import requests | ||
from requests_oauthlib import OAuth1 | ||
import os | ||
import functions_framework | ||
import json | ||
|
||
|
||
consumer_key = os.environ.get("CONSUMER_KEY") | ||
consumer_secret = os.environ.get("CONSUMER_SECRET") | ||
access_token = os.environ.get("ACCESS_TOKEN") | ||
token_secret = os.environ.get("TOKEN_SECRET") | ||
|
||
payload = {"text": "Public Goods are Good"} | ||
|
||
|
||
def connect_to_oauth(consumer_key, consumer_secret, acccess_token, | ||
token_secret): | ||
url = "https://api.twitter.com/2/tweets" | ||
auth = OAuth1(consumer_key, consumer_secret, acccess_token, token_secret) | ||
return url, auth | ||
|
||
|
||
@functions_framework.cloud_event | ||
def hello_pubsub(cloud_event): | ||
|
||
url, auth = connect_to_oauth( | ||
consumer_key, consumer_secret, access_token, token_secret | ||
) | ||
request = requests.post( | ||
auth=auth, url=url, json=payload, headers={ | ||
"Content-Type": "application/json"} | ||
) | ||
|
||
if request.status_code != 201: | ||
raise Exception( | ||
"Request returned an error: {} {}".format( | ||
request.status_code, | ||
request.text) | ||
) | ||
print("Response code: {}".format(request.status_code)) | ||
|
||
# Saving the response as JSON | ||
json_request = request.json() | ||
print(json.dumps(json_request, indent=4, sort_keys=True)) |
This file was deleted.
Oops, something went wrong.