Get that crucial report in Slack Channel

pip install google-cloud-bigqueryfrom google.cloud import bigquery#setting up authourization
client = bigquery.Client.from_service_account_json("your_keys.json")
#query you are interested in my_query = """

select * from my_table
where my_condition = 'my_condition';
"""
#making the API request and get the data into dataframedf = client.query(my_query).to_dataframe()if df.empty:
print('no results, please check query or if table is populated')
else:
print("Fetch data success,", len(df))
ax = df.plot(kind='bar', figsize=(20,16), color="green", fontsize=13)

ax.set_alpha(0.8)

ax.set_title("Stats_Today", fontsize=22)

ax.set_ylabel("Record Count", fontsize=15)

ax.set_xlabel("Date", fontsize=15)

fig = ax.get_figure()

#saving figure at folder, saving at airflow folder
fig.savefig(airflow_home+'Stats_Today.png', bbox_inches = "tight")
#reading variables from the file, these are coming from airflowkpi_variables = Variable.get("kpi_variables_secret", deserialize_json=True)

url = kpi_variables["url"]
def upload_graph():
#uploading to slack
querystring = {"token":access_token}
payload = {"channels":"my_channel"} #your channel
file_upload = {"file": (airflow_home+"Stats_Today.png", open(airflow_home+"Stats_Today.png", 'rb'), 'image/png')}
headers = {"Content-Type": "multipart/form-data",}
response = requests.post(url, data=payload, params=querystring, files=file_upload)

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Joyent CoPilot: Bringing Application Awareness to Cloud Infrastructure. Part I.

C++ Tutorial for Complete Beginners

Symptoms of Failing Scaling: Bottlenecks, Chaos and the Wizard of Oz

Certified Kubernetes Deployments Made Easy with WebSphere Liberty Cloud Pak

Sentiance SDK in Flutter

Make the Raspberry Pi visible on Mac and Windows computers

Demystifying Trees in Data Structures — Part 1

The big old reliable elephant: talking about Postgres with Craig Kerstiens

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Siya

Siya

More from Medium

Enhancing the Database connection using Amazon RDS Proxy

How to use DAG to tigger another DAG in Airflow?

Building a customized Spark metrics collection tool for a global enterprise technology provider

Apache Oozie Monitoring