Skip to content

Commit

Permalink
chore: Add new version of GCP reminder function
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanmolto committed Oct 29, 2023
1 parent 1b7d7c6 commit 2833fc7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 110 deletions.
44 changes: 44 additions & 0 deletions gcp_gitcoin_reminder_tweet.py
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))
110 changes: 0 additions & 110 deletions gitcoin_reminder_tweet.py

This file was deleted.

0 comments on commit 2833fc7

Please sign in to comment.