Inside cloud functions I have this functions (entry point)
def hello_http(request):
Inside that function I have all this code
What this does Is to download spreadsheet of prices like btc_usd and then put this data frame on mysql google data base
To call this function I use http
And then on Cloud scheduler I pasted the url using POST method
import pandas as pd
import requests
import sqlalchemy
import mysql.connector
import pandas as pd
import numpy as np
import requests
class BitsoAPI:
def __init__(self, api_key, api_secret):
self.api_key = api_key
self.api_secret = api_secret
self.base_url = "https://api.bitso.com/v3/"
def get_daily_prices(self, book="btc_usd"):
response = requests.get('https://api.bitso.com/v3/trades/?book='+book)
json_response = response.json()
datos = json_response['payload']
df = pd.DataFrame(datos)
df['fecha'] = pd.to_datetime(df['created_at'],utc=True, format='ISO8601')
del df['created_at']
return df
def get_books(self):
'''Returns a list with names of avaiable books for book parameter from
get daily prices function'''
response = requests.get(self.base_url + 'available_books/')
json_response = response.json()
books = [book['book'] for book in json_response['payload']]
return books
def store_data_in_sql(df, table_name='ok'):
# Establish connection to MySQL database
connection = mysql.connector.connect(
host=db_host,
user=db_user,
password=db_password,
database=db_name
)
# Create MySQL cursor
cursor = connection.cursor()
# Insert the DataFrame into the MySQL table
df.to_sql(table_name, con=engine, if_exists='append', index=False)
# Commit changes and close connection
connection.commit()
connection.close()
for book in books:
bitso_api = BitsoAPI(api_key, api_secret)
df = bitso_api.get_daily_prices(book=book)
store_data_in_sql(df,table_name=book)
But then I got ‘Failed’ everytime I run it on Scheduler, even tho I could created the function on Cloud Functions